/*
 * 지쿠폰 모니터 — 리프리즘(iblog /monitor) 톤을 그대로 따른다.
 * WDS (Wanted Design System / Montage) 다크 토큰 · MIT — github.com/wanteddev/montage-web
 *
 * 규칙(리프리즘과 동일): 색은 아래 변수만, 간격은 8px 그리드만.
 * 살아 있음 = --positive, 사람이 손대야 함 = --negative, 곧 볼 것 = --cautionary 로 고정한다.
 */
@font-face {
  font-family: 'Pretendard Variable';
  src: url('fonts/PretendardVariable.woff2') format('woff2-variations');
  font-weight: 45 920;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #1b1c1e;
  --bg-alt: #0f0f10;
  --surface: #212225;
  --line: #46474c;
  --line-soft: rgba(70, 71, 76, 0.4);
  --label-strong: #ffffff;
  --label-normal: #f7f7f8;
  --label-sub: #aeafb2;
  --label-alt: #8b95a1;

  --primary: #3385ff;
  --primary-strong: #1a75ff;

  --positive: #1ed45a;
  --cautionary: #ff9200;
  --negative: #ff4242;

  --violet: #6541f2;
  --purple: #cb59ff;
  --cyan: #00bdde;
  --gold: #e6b800;
  --rose: #ff5c8a;

  --s2: 2px; --s4: 4px; --s6: 6px; --s8: 8px;
  --s12: 12px; --s16: 16px; --s20: 20px; --s24: 24px;
  --s32: 32px; --s40: 40px; --s48: 48px;

  --r-s: 8px; --r-m: 10px; --r-l: 12px;

  --font: 'Pretendard Variable', 'Malgun Gothic', -apple-system, sans-serif;
}

* { box-sizing: border-box; }
/* .alert 등 display 를 지정한 클래스가 hidden 속성을 이기지 않게 한다 */
[hidden] { display: none !important; }

html, body { background: var(--bg); }
body {
  margin: 0;
  padding: var(--s32);
  color: var(--label-normal);
  font-family: var(--font);
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 32px; line-height: 44px; font-weight: 700; letter-spacing: -0.02em; color: var(--label-strong); margin: 0; }
h2 { font-size: 18px; line-height: 26px; font-weight: 700; letter-spacing: -0.01em; color: var(--label-strong); margin: 0; }
h3 { font-size: 14px; line-height: 20px; font-weight: 600; color: var(--label-strong); margin: 0; }

.t-label  { font-size: 14px; line-height: 20px; font-weight: 500; }
.t-caption{ font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0.01em; }
.t-sub    { color: var(--label-sub); }
.t-mono   { font-variant-numeric: tabular-nums; }
.t-neg    { color: var(--negative); }
.t-warn   { color: var(--cautionary); }
.t-pos    { color: var(--positive); }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── 네비게이션 ───────────────────────────────────── */
.nav {
  display: flex;
  gap: var(--s24);
  align-items: center;
  margin-bottom: var(--s32);
  padding-bottom: var(--s16);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  row-gap: var(--s8);
}
.nav a {
  color: var(--label-sub);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  padding: var(--s6) 0;
}
.nav a:hover { color: var(--label-strong); text-decoration: none; }
/* 지금 보고 있는 페이지 */
.nav a.is-on { color: var(--label-strong); box-shadow: inset 0 -2px 0 var(--label-strong); }
.nav .brand { color: var(--label-strong); font-weight: 700; font-size: 16px; margin-right: var(--s8); }
.nav form { margin-left: auto; }

/* ── 공통 요소 ───────────────────────────────────── */
button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  color: var(--label-normal);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: var(--s8) var(--s16);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--label-sub); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--primary-strong); border-color: var(--primary-strong); }
button.linkish { background: none; border: none; color: var(--label-sub); padding: var(--s6) 0; font-size: 13px; }
button.linkish:hover { color: var(--label-strong); }

input[type='password'] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  color: var(--label-normal);
  font-family: var(--font);
  font-size: 16px;
  padding: var(--s12);
}
input:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.badge {
  display: inline-block;
  padding: var(--s2) var(--s8);
  border-radius: var(--r-s);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  white-space: nowrap;
}
.badge--ok    { background: rgba(30, 212, 90, 0.14); color: var(--positive); }
.badge--warn  { background: rgba(255, 146, 0, 0.16); color: var(--cautionary); }
.badge--err   { background: rgba(255, 66, 66, 0.14); color: var(--negative); }
.badge--info  { background: rgba(51, 133, 255, 0.16); color: var(--primary); }
.badge--muted { background: var(--surface); color: var(--label-sub); }
.badge--purple{ background: rgba(203, 89, 255, 0.14); color: var(--purple); }

.chip {
  display: inline-block;
  padding: var(--s2) var(--s8);
  border-radius: var(--r-s);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface);
  color: var(--label-sub);
}
.chip--lounge    { background: rgba(0, 189, 222, 0.16);  color: var(--cyan); }
.chip--push      { background: rgba(101, 65, 242, 0.18); color: #a996ff; }
.chip--site      { background: rgba(230, 184, 0, 0.18);  color: var(--gold); }
.chip--sitelink  { background: rgba(203, 89, 255, 0.16); color: var(--purple); }
.chip--keepalive { background: rgba(255, 92, 138, 0.16); color: var(--rose); }

/* ── 표 ──────────────────────────────────────────── */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--label-sub);
  padding: 0 var(--s12) var(--s8);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: var(--s8) var(--s12);
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
  line-height: 20px;
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--surface); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .title-cell { min-width: 220px; max-width: 420px; }
.row-err  { background: rgba(255, 66, 66, 0.08); }
.row-warn { background: rgba(255, 146, 0, 0.08); }

/* ── 페이지 골격 ─────────────────────────────────── */
.monitor { display: flex; flex-direction: column; gap: var(--s40); }
.dash-sec { display: flex; flex-direction: column; gap: var(--s16); scroll-margin-top: var(--s16); }
.dash-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s16);
  flex-wrap: wrap;
}
.dash-subhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s12);
  flex-wrap: wrap;
}
.note { margin: 0; max-width: 92ch; }

.card {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: var(--s16);
  min-width: 0;
}

/* ── 지금 볼 것 ──────────────────────────────────── */
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s8); }
.alert {
  border-radius: var(--r-m);
  padding: var(--s12) var(--s16);
  font-size: 14px;
  line-height: 20px;
  display: flex;
  gap: var(--s12);
  align-items: flex-start;
}
.alert b { display: block; font-weight: 700; }
.alert span { color: var(--label-normal); opacity: 0.85; }
.alert--ok   { background: rgba(30, 212, 90, 0.10);  border: 1px solid rgba(30, 212, 90, 0.35);  color: var(--positive); }
.alert--info { background: rgba(51, 133, 255, 0.10); border: 1px solid rgba(51, 133, 255, 0.35); color: var(--primary); }
.alert--warn { background: rgba(255, 146, 0, 0.10);  border: 1px solid rgba(255, 146, 0, 0.35);  color: var(--cautionary); }
.alert--error{ background: rgba(255, 66, 66, 0.10);  border: 1px solid rgba(255, 66, 66, 0.35);  color: var(--negative); }

/* ── 루틴 카드 ───────────────────────────────────── */
.routines { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s12); }
.routine {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: var(--s12) var(--s16);
  display: flex;
  flex-direction: column;
  gap: var(--s8);
  min-width: 0;
  text-align: left;
  font-weight: 400;
  width: 100%;
}
.routine:hover { border-color: var(--label-sub); }
.routine.is-ok   { border-color: rgba(30, 212, 90, 0.45); background: rgba(30, 212, 90, 0.05); }
.routine.is-hang { border-color: rgba(255, 146, 0, 0.55); background: rgba(255, 146, 0, 0.06); }
.routine.is-down { border-color: rgba(255, 66, 66, 0.55); background: rgba(255, 66, 66, 0.06); }
.routine.is-legacy { border-color: rgba(51, 133, 255, 0.45); }
.routine-head { display: flex; align-items: center; gap: var(--s8); }
.routine-name { font-size: 15px; line-height: 22px; font-weight: 700; color: var(--label-strong); }
.routine-state { margin-left: auto; }
.routine-line { font-size: 13px; line-height: 18px; color: var(--label-normal); overflow-wrap: anywhere; }
.routine-meta { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s12); }

.progress { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--positive); border-radius: 3px; transition: width .4s ease; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; display: block; }
.dot--ok { background: var(--positive); animation: dash-pulse 1.6s ease-in-out infinite; }
.dot--hang { background: var(--cautionary); }
.dot--down { background: var(--negative); }
.dot--legacy { background: var(--primary); }
.dot--done, .dot--off { background: var(--line); }
.dot--wait { background: var(--label-alt); animation: dash-breathe 2.6s ease-in-out infinite; }
@keyframes dash-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes dash-breathe { 0%, 100% { opacity: 0.9; } 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .dot--ok, .dot--wait { animation: none; } }

/* ── 지표 ────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s12); }
.kpi {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: var(--s12);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  min-width: 0;
}
.kpi-label { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--label-sub); letter-spacing: 0.03em; }
.kpi-value { font-size: 26px; line-height: 34px; font-weight: 700; color: var(--label-strong); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; font-weight: 600; color: var(--label-sub); margin-left: var(--s2); }
.kpi-value.is-neg { color: var(--negative); }
.kpi-value.is-warn { color: var(--cautionary); }
.kpi-value.is-pos { color: var(--positive); }
.kpi-sub { font-size: 12px; line-height: 16px; color: var(--label-sub); }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--s16); align-items: start; }

/* ── 그래프 ──────────────────────────────────────── */
.chart { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--label-sub); font-size: 10px; font-family: var(--font); }
.chart .bar-pos { fill: var(--positive); }
.chart .bar-neg { fill: var(--negative); }
.chart .bar-pri { fill: var(--primary); }
.chart .bar-mut { fill: var(--line); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: rgba(255, 255, 255, 0.05); }
.legend { display: flex; gap: var(--s16); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: var(--s6); font-size: 12px; line-height: 16px; color: var(--label-sub); }
.legend i { width: 9px; height: 9px; border-radius: var(--s2); display: block; }
.spark { display: inline-block; vertical-align: middle; }
.spark polyline { fill: none; stroke: var(--primary); stroke-width: 1.5; }

/* ── 세그먼트 필터 ───────────────────────────────── */
.seg { display: inline-flex; gap: var(--s4); flex-wrap: wrap; }
.seg button { padding: var(--s4) var(--s12); font-size: 13px; border-radius: var(--r-s); color: var(--label-sub); }
.seg button.is-on { color: var(--label-strong); border-color: var(--primary); background: rgba(51, 133, 255, 0.12); }

/* ── 이벤트 ──────────────────────────────────────── */
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.events li {
  display: grid;
  grid-template-columns: 92px auto 1fr;
  gap: var(--s12);
  align-items: baseline;
  padding: var(--s8) 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  line-height: 18px;
}
.events li:last-child { border-bottom: none; }
.events .msg { overflow-wrap: anywhere; }
.ev-error .msg { color: var(--negative); }
.ev-warn .msg { color: var(--cautionary); }
.ev-success .msg { color: var(--positive); }

/* ── 로그 패널 ───────────────────────────────────── */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.drawer.is-open { display: flex; }
.drawer-box {
  width: min(960px, 100%);
  max-height: 80vh;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-l) var(--r-l) 0 0;
  padding: var(--s16);
  display: flex;
  flex-direction: column;
  gap: var(--s12);
}
.log {
  background: #08090a;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  color: var(--label-normal);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  line-height: 18px;
  overflow: auto;
  padding: var(--s12);
  white-space: pre-wrap;
  margin: 0;
  flex: 1;
  min-height: 200px;
}
.log .l-error { color: var(--negative); }
.log .l-warn { color: var(--cautionary); }
.log time { color: var(--label-alt); margin-right: var(--s8); }

/* ── 로그인 ──────────────────────────────────────── */
.login {
  max-width: 360px;
  margin: 12vh auto 0;
  display: flex;
  flex-direction: column;
  gap: var(--s16);
}
.login form { display: flex; flex-direction: column; gap: var(--s12); }

.empty { padding: var(--s16); text-align: center; color: var(--label-sub); font-size: 14px; }
.more { align-self: flex-start; }

/* ── 휴대폰 ──────────────────────────────────────── */
@media (max-width: 720px) {
  body { padding: var(--s16); }
  h1 { font-size: 24px; line-height: 32px; }
  .nav { gap: var(--s16); margin-bottom: var(--s24); }
  .monitor { gap: var(--s32); }
  .routines { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 22px; line-height: 30px; }
  .events li { grid-template-columns: 1fr; gap: var(--s2); }
  .table .title-cell { min-width: 180px; }
}

.legend .lg-pos { background: var(--positive); }
.legend .lg-neg { background: var(--negative); }
.legend .lg-mut { background: var(--line); }
.legend .lg-pri { background: var(--primary); }
