:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --ink: #16252b;
  --muted: #5b6b70;
  --line: #d5dcda;
  --side: #16252b;
  --side-ink: #dfe9e7;
  --side-muted: #8fa5a3;
  --accent: #0b6b63;
  --accent-ink: #ffffff;
  --accent-soft: #d7ece8;
  --warn: #8a5600;
  --warn-soft: #fbebcb;
  --danger: #b3261e;
  --danger-soft: #f8dad7;
  --idle: #c3cdcb;
  --radius: 6px;
  --font: "Pretendard Variable", Pretendard, "Noto Sans KR", "Apple SD Gothic Neo",
    "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; line-height: 1.3; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.4em; font-size: 14px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- 로그인 ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px; display: grid; gap: 16px;
}

/* ---------- 레이아웃 ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
.side {
  background: var(--side); color: var(--side-ink); padding: 24px 14px;
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 17px; font-weight: 700; padding: 0 10px; letter-spacing: -0.01em; }
.nav { display: grid; gap: 2px; }
.side-foot { margin-top: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--radius); color: var(--side-ink); text-decoration: none;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.07); }
.nav-link[aria-current="page"] { background: rgba(255, 255, 255, 0.14); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.on { background: #4fd1b5; }
.dot.err { background: #ff8a80; }
.dot.soon { background: transparent; border: 1.5px solid var(--side-muted); }
.nav-link .tag { margin-left: auto; font-size: 12px; color: var(--side-muted); }

.main { padding: 20px 32px 48px; min-width: 0; }
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 20px; }
.view { max-width: 1040px; display: grid; gap: 20px; }

/* ---------- 공통 부품 ---------- */
.btn {
  font: inherit; font-weight: 600; padding: 8px 14px; min-height: 38px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.pill {
  font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; min-height: 34px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.pill.test { background: var(--warn-soft); border-color: #e7c982; color: var(--warn); }
.pill.live { background: var(--accent-soft); border-color: #9fcfc7; color: var(--accent); }

.banner {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px;
  background: var(--danger-soft); color: #7d1a14; display: flex; gap: 12px;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }

.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.field input, .field select {
  font: inherit; font-weight: 400; padding: 8px 10px; min-height: 40px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
.row { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.row .field input[type="number"] { width: 110px; }

/* 켜기/끄기 스위치 */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 24px; border-radius: 999px; background: var(--idle); position: relative; transition: background 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

/* 기능 목록 (개요) */
.mod-list { display: grid; }
.mod-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.mod-row:first-child { border-top: 0; padding-top: 0; }
.mod-row a { color: inherit; text-decoration: none; font-weight: 700; font-size: 16px; }
.mod-row a:hover { text-decoration: underline; }
.badge { font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--idle); color: var(--ink); white-space: nowrap; height: fit-content; }
.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* 실행 띠: 최근 48회 */
.tape { display: grid; grid-template-columns: repeat(48, minmax(0, 1fr)); gap: 3px; height: 36px; align-items: end; }
.tick { height: 100%; border-radius: 2px; background: var(--idle); opacity: 0.45; }
.tick.empty { height: 40%; }
.tick.ok { background: var(--accent); opacity: 0.35; height: 55%; }
.tick.fixed { background: var(--accent); opacity: 1; height: 100%; }
.tick.error { background: var(--danger); opacity: 1; height: 100%; }
.tick.partial { background: var(--warn); opacity: 1; height: 100%; }
.tick.stopped { background: var(--idle); opacity: 1; height: 55%; }
.tick.test { background: transparent; border: 1.5px solid var(--accent); }
.tick.test.error { border-color: var(--danger); }
.tick.test.partial { border-color: var(--warn); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 14px; border-radius: 2px; display: inline-block; background: var(--idle); }
.legend i.ok { background: var(--accent); opacity: 0.35; }
.legend i.fixed { background: var(--accent); }
.legend i.partial { background: var(--warn); }
.legend i.error { background: var(--danger); }
.legend i.stopped { background: var(--idle); }
.legend i.test { background: transparent; border: 1.5px solid var(--accent); }

/* 요약 수치 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { border-left: 3px solid var(--line); padding-left: 12px; }
.stat b { display: block; font-size: 22px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.fixed { border-color: var(--accent); }
.stat.errors { border-color: var(--danger); }

/* 표 */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px 8px 0; border-top: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); border-top: 0; font-size: 13px; }
td.num, th.num { text-align: right; }
.empty-note { color: var(--muted); padding: 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink);
  color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }

/* ---------- 모바일 ---------- */
.tabbar { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 14px 16px calc(84px + env(safe-area-inset-bottom, 0px)); }
  h1 { font-size: 21px; }
  .card { padding: 16px; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; background: var(--side);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  }
  .tabbar a {
    display: grid; justify-items: center; gap: 2px; padding: 8px 2px; font-size: 12px;
    color: var(--side-muted); text-decoration: none; border-radius: var(--radius);
  }
  .tabbar a[aria-current="page"] { color: #fff; background: rgba(255, 255, 255, 0.12); font-weight: 600; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
  .tape { gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .switch .track, .switch .track::after, .toast { transition: none; }
}

/* ---------- 업체 선택 칩, 모드 전환 ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  font: inherit; font-weight: 600; font-size: 14px; padding: 8px 14px; min-height: 40px;
  border: 0; background: var(--surface); color: var(--muted); cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.on.test { background: var(--warn-soft); color: var(--warn); }
.seg-btn.on.live { background: var(--accent); color: var(--accent-ink); }
.mode-note { font-size: 13px; color: var(--muted); }
.mod-title { font-weight: 700; font-size: 16px; }
