/* 공통 컴포넌트: 헤더, 버튼, 칩, 상태 배지, 게이지, 표, 탭, 빈 화면 등 */

.icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== 앱 틀: 왼쪽 메뉴 + 본문 (관리자 대시보드) ===== */
.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  background: var(--side-bg);
  color: var(--side-ink);
  border-right: 1px solid var(--side-line);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar :focus-visible {
  outline-color: var(--brand);
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: var(--header-h);
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--side-line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--side-ink-hi);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  background: var(--brand);
  color: var(--brand-ink);
  font-family: var(--font-num);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-title {
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.sidebar .sidebar-close {
  display: none;
  margin-left: auto;
  border-color: var(--side-line);
  background: transparent;
  color: var(--side-ink);
}
.sidebar .sidebar-close:hover {
  background: var(--side-hover);
  color: var(--side-ink-hi);
}

.side-nav {
  flex: 1;
  padding: 8px 10px 20px;
}
.side-group {
  display: none; /* 메뉴 묶음 제목은 숨긴다 (글자 줄이기) */
  margin: 18px 0 6px;
  padding: 0 12px;
  color: var(--side-ink-2);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.side-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--tap);
  margin-bottom: 6px;
  padding: 0 14px;
  border-radius: var(--r-md);
  color: var(--side-ink);
  font-size: var(--fs-lg);
  font-weight: 700;
  text-decoration: none;
}
.side-link:hover {
  background: var(--side-hover);
  color: var(--side-ink-hi);
}
.side-link[aria-current="page"] {
  background: var(--side-active);
  color: var(--side-ink-hi);
}
.side-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 9px;
  bottom: 9px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--brand);
}
.side-link[aria-current="page"] .icon {
  color: var(--brand);
}

.app-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-w);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar .menu-btn {
  display: none;
}
.topbar-path {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--ink-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.topbar-path strong {
  color: var(--ink);
  font-size: var(--fs-md);
}
.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.scrim {
  display: none;
}

/* 실시간 연결 표시 */
.live {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 150px; /* 글자가 바뀌어도 상단 바의 폭이 변하지 않게 */
  height: 48px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: var(--fs-md);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.live:hover {
  border-color: var(--ink-3);
}
.live[data-state="busy"] .live-dot {
  background: var(--warn-solid);
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink {
  50% {
    opacity: 0.25;
  }
}
.live-dot {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--off-solid);
}
.live[data-state="live"] .live-dot {
  background: var(--good-solid);
  animation: pulse 2.4s ease-out infinite;
}
.live[data-state="paused"] .live-dot {
  background: var(--warn-solid);
}
.live[data-state="error"] {
  color: var(--crit-fg);
  border-color: var(--crit-solid);
  background: var(--crit-bg);
}
.live[data-state="error"] .live-dot {
  background: var(--crit-solid);
}
.live-time {
  font-family: var(--font-num);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--good-solid) 45%, transparent);
  }
  70%,
  100% {
    box-shadow: 0 0 0 7px transparent;
  }
}

/* 좁은 화면(태블릿·모바일): 왼쪽 메뉴는 햄버거 버튼으로 여는 서랍(드로어) */
@media (max-width: 1023px) {
  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform 0.22s ease,
      visibility 0s linear 0.22s;
  }
  .nav-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-pop);
    transition:
      transform 0.22s ease,
      visibility 0s;
  }
  .sidebar .sidebar-close {
    display: inline-flex;
  }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: rgba(0, 0, 0, 0.58);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .nav-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
  .nav-open {
    overflow: hidden;
  }
  .app-main {
    margin-left: 0;
  }
  .topbar {
    padding: 0 12px;
  }
  .topbar .menu-btn {
    display: inline-flex;
  }
  .live {
    min-width: 0;
    padding: 0 12px;
  }
}

/* ===== 버튼 / 입력 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 22px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.12s,
    border-color 0.12s;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--ink-3);
}
.btn-primary {
  background: var(--brand);
  border-color: var(--brand-edge);
  color: var(--brand-ink);
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-edge);
}
.btn-danger {
  color: var(--crit-fg);
  border-color: var(--crit-line);
}
.btn-danger:hover {
  background: var(--crit-bg);
  border-color: var(--crit-fg);
}
.btn-sm {
  min-height: 48px;
  padding: 0 16px;
  font-size: var(--fs-md);
}
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.field > span {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--ink-2);
}
select,
input[type="text"],
input[type="search"],
input[type="password"],
input[type="url"],
input[type="date"],
textarea {
  min-height: var(--tap);
  padding: 0 14px;
  border: 2px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-md);
  min-width: 0;
}
input::placeholder {
  color: var(--ink-3);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search > [data-icon] {
  position: absolute;
  left: 14px;
  top: 50%;
  display: flex;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.search input {
  width: 100%;
  padding-left: 46px;
}

/* 스위치 */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-track {
  position: relative;
  width: 60px;
  height: 34px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background-color 0.15s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track {
  background: var(--good-solid);
}
.switch input:checked + .switch-track::after {
  transform: translateX(26px);
}
.switch input:focus-visible + .switch-track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* 칩(필터) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
}
.chip:hover {
  background: var(--surface-2);
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}
.chip-count {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

/* 분할 버튼 (2~3개 중 선택) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
}
.segmented button {
  min-height: var(--tap);
  padding: 0 26px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
}
.segmented button:last-child {
  border-right: 0;
}
.segmented button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
}

/* ===== 상태 배지 (아이콘 + 글자) ===== */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px 0 14px;
  border: 2px solid;
  border-radius: 999px;
  font-size: var(--fs-lg);
  font-weight: 800;
  white-space: nowrap;
}
.status .icon {
  width: 24px;
  height: 24px;
}
.status-ok {
  color: var(--good-fg);
  background: var(--good-bg);
  border-color: var(--good-line);
}
.status-crit {
  color: var(--crit-fg);
  background: var(--crit-bg);
  border-color: var(--crit-line);
}
.status-off {
  color: var(--off-fg);
  background: var(--off-bg);
  border-color: var(--off-line);
}

.code {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--crit-line);
  border-radius: var(--r-sm);
  background: var(--crit-bg);
  color: var(--crit-fg);
  font-family: ui-monospace, "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

/* ===== 패널 ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-title {
  font-size: var(--fs-lg);
}
.panel-body {
  padding: 18px;
}

/* ===== 안내 상자(콜아웃) ===== */
.callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid;
  border-radius: var(--r-md);
}
.callout .icon {
  margin-top: 2px;
}
.callout-warn {
  color: var(--warn-fg);
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.callout-crit {
  color: var(--crit-fg);
  background: var(--crit-bg);
  border-color: var(--crit-line);
}
.callout-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.callout-text {
  color: var(--ink);
}


/* ===== 계기판식 게이지 ===== */
.gauge {
  min-width: 0;
}
.gauge-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 28px;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--ink-2);
}
.gauge-flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--crit-fg);
  font-weight: 800;
  white-space: nowrap;
}
.gauge-flag[data-on="0"] {
  visibility: hidden; /* 자리는 항상 차지해서 경고가 떠도 위치가 움직이지 않는다 */
}
.gauge-flag .icon {
  width: 20px;
  height: 20px;
}
.gauge-read {
  display: flex;
  flex-wrap: nowrap; /* 숫자와 단위가 줄바꿈되어 높이가 변하지 않게 */
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  margin-top: 2px;
  line-height: 1.05;
}
.gauge-val {
  font-family: var(--font-num);
  font-size: 64px;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.gauge-unit {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--ink-2);
}
.gauge-track {
  position: relative;
  height: 14px;
  margin-top: 10px;
  border-radius: 2px;
  background: var(--surface-3);
}
.gauge-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--zone-from, 0%);
  width: calc(var(--zone-to, 0%) - var(--zone-from, 0%));
  border-radius: 2px;
  background: var(--crit-line);
  opacity: 0.6;
}
.gauge-band {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--band-from, 0%);
  width: calc(var(--band-to, 0%) - var(--band-from, 0%));
  border-radius: 2px;
  background: var(--good-line);
  opacity: 0.7;
}
.gauge-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--pct, 0%);
  border-radius: 2px;
  background: var(--series-1);
  transition: width 0.6s ease;
}
.gauge-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--tick, 0%);
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}
.gauge.is-bad .gauge-fill {
  background: var(--crit-solid);
}
.gauge.is-bad .gauge-val {
  color: var(--crit-fg);
}
.gauge.is-empty .gauge-val {
  color: var(--ink-3);
}
.gauge-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--fs-sm);
  color: var(--ink-3);
}
.gauge-lg .gauge-val {
  font-size: 76px;
}
.gauge-lg .gauge-track {
  height: 16px;
}
.gauge-lg .gauge-label {
  font-size: var(--fs-lg);
}

/* ===== 탭 ===== */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  margin-bottom: -1px;
  padding: 0 22px;
  border: 0;
  border-bottom: 4px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-md);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover {
  color: var(--ink);
  background: var(--surface-2);
}
.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--brand);
}
.tab-count {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-3);
  font-family: var(--font-num);
  font-size: 15px;
  line-height: 22px;
  text-align: center;
}
.tab-count.is-alert {
  background: var(--crit-bg);
  color: var(--crit-fg);
}

/* ===== 표 ===== */
.table-wrap {
  overflow: auto;
}
.table-scroll {
  max-height: 560px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table tbody tr:hover td {
  background: var(--surface-2);
}
.table .col-num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table .row-warn td:first-child {
  box-shadow: inset 4px 0 0 var(--crit-solid);
}
.cell-sub {
  font-size: var(--fs-xs);
  color: var(--ink-2);
}
.pill {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.is-bad {
  border-color: var(--crit-line);
  background: var(--crit-bg);
  color: var(--crit-fg);
}

/* ===== 로딩 / 빈 화면 / 알림창 ===== */
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-3),
    var(--surface-2),
    var(--surface-3)
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 40px 16px;
  text-align: center;
  color: var(--ink-2);
}
.empty .icon {
  width: 32px;
  height: 32px;
  color: var(--ink-3);
}
.empty-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--ink);
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 90;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-pop);
  font-weight: 600;
}

@media (max-width: 760px) {
  .btn,
  .icon-btn,
  select,
  input[type="text"],
  input[type="search"] {
    min-height: 44px;
  }
  .btn-sm {
    min-height: 40px;
  }
  select,
  input[type="text"],
  input[type="search"] {
    font-size: 16px; /* iOS 에서 입력 시 화면이 확대되지 않게 */
  }
  .toast-host {
    bottom: calc(var(--tabbar-h) + 16px);
  }

  /* 표 → 세로 카드 */
  .table thead {
    display: none;
  }
  .table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
    width: 100%;
  }
  .table tr {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
  }
  .table td {
    padding: 4px 0;
    border: 0;
  }
  .table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--ink-2);
  }
  .table tbody tr:hover td {
    background: transparent;
  }
  .table .row-warn td:first-child {
    box-shadow: none;
  }
  .table .row-warn {
    border-left: 4px solid var(--crit-solid);
  }
  .table-scroll {
    max-height: none;
  }
}
