/* MyDash — 다크 테마 공통 스타일 */
:root {
  --bg: #16181c;
  --surface: #1f2228;
  --surface-2: #272b32;
  --border: #33373f;
  --text: #e6e8eb;
  --muted: #9aa1ab;
  --accent: #3b82f6;
  --accent-hover: #2f6fd8;
  --ok: #34c77b;
  --warn: #f2b33d;
  --bad: #f06a6a;
  --radius: 10px;
  --mono: Consolas, "D2Coding", "Cascadia Mono", Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: #ffd580;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

button.secondary:hover {
  background: #30353d;
}

button.danger {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}

button.danger:hover {
  background: rgba(240, 106, 106, 0.12);
}

/* ───────── 로그인 ───────── */
body.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.login-card .brand {
  margin: 0;
  font-size: 1.5rem;
  text-align: center;
}

.login-card .subtitle {
  margin: 0.25rem 0 1.5rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.login-card label {
  display: block;
  margin: 1rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.login-card button {
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.7rem;
}

.alert {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: rgba(240, 106, 106, 0.12);
  border: 1px solid rgba(240, 106, 106, 0.4);
  color: var(--bad);
  font-size: 0.9rem;
}

/* ───────── 대시보드 ───────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(22, 24, 28, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner,
main {
  max-width: 1040px;
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 60px;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
}

.brand-block .brand {
  margin: 0;
  font-size: 1.15rem;
}

.brand-block .host {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
}

.live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.live.connected .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(52, 199, 123, 0.2);
}

.live.disconnected .dot {
  background: var(--bad);
}

.user {
  color: var(--muted);
}

main {
  padding-top: 1.75rem;
  padding-bottom: 4rem;
}

section {
  margin-bottom: 2.5rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.section-head .meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* 지표 카드 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
}

.stat {
  padding: 1rem 1.1rem;
}

.stat .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat .value {
  margin-top: 0.3rem;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat .detail {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  margin-top: 0.7rem;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: inherit;
  transition: width 0.4s ease, background-color 0.4s ease;
}

.bar > span.warn { background: var(--warn); }
.bar > span.bad  { background: var(--bad); }

/* 표 */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.5rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

td.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill.open {
  background: rgba(52, 199, 123, 0.12);
  color: var(--ok);
}

/* 열려 있어야 하는데 닫힌 포트 — 빨강. 평소 닫힘(expectOpen: false)은 회색 + 줄 흐리게 */
.pill.down {
  background: rgba(240, 106, 106, 0.12);
  color: var(--bad);
}

.pill.idle {
  color: var(--muted);
}

tbody tr.is-down td {
  background: rgba(240, 106, 106, 0.05);
}

tbody tr.is-idle td {
  opacity: 0.55;
}

.section-head .meta.bad {
  color: var(--bad);
}

/* 언어 배지 — 색은 GitHub linguist 언어 색 */
.svc-name {
  margin-right: 0.5rem;
}

.lang {
  --lang: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.1rem 0.3rem 0.1rem 0;
  padding: 0.05rem 0.5rem 0.05rem 0.45rem;
  border: 1px solid color-mix(in srgb, var(--lang) 45%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lang) 12%, transparent);
  color: color-mix(in srgb, var(--lang) 70%, var(--text));
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  vertical-align: 1px;
  cursor: default;
}

.lang::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lang);
}

.lang-javascript { --lang: #f1e05a; }
.lang-typescript { --lang: #4b8fe0; } /* linguist #3178c6 — 어두운 배경에서 조금 밝게 */
.lang-java       { --lang: #d08a3a; } /* linguist #b07219 — 〃 */
.lang-python     { --lang: #5a9bd5; }
.lang-csharp     { --lang: #3fb950; }
.lang-go         { --lang: #00add8; }

.lang-system {
  --lang: #6b7280;
  font-weight: 500;
}

.port-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.port-rules code {
  color: var(--text);
}

/* 관리 작업 */
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.1rem;
}

.actions + .actions {
  border-top: 1px solid var(--border);
}

.actions .text strong {
  display: block;
}

.actions .text span {
  color: var(--muted);
  font-size: 0.85rem;
}

.actions form {
  margin: 0;
}

.footer-note {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* 어떻게 동작하나 — 텍스트 다이어그램 */
.howto details {
  margin: 0 0 0.6rem;
  padding: 0.2rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.howto summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.6rem 0;
}

.howto pre {
  margin: 0.3rem 0 0.6rem;
  padding: 0.8rem;
  background: #121317;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.35;
  white-space: pre;
  color: #9cdcfe;
}

.howto .notes {
  margin: 0.4rem 0 0.8rem;
  padding-left: 1.4rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.howto ul.notes {
  list-style: disc;
}

.howto .notes li {
  margin: 0.2rem 0;
}

@media (max-width: 860px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  .topbar-inner {
    height: auto;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    flex-wrap: wrap;
  }

  .brand-block .host,
  .user {
    display: none;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}

/* 백업 카드 — pill 은 포트 표와 같은 모양을 쓰되 상태 이름만 다르다 */
.pill.ok    { background: rgba(52, 199, 123, 0.12); color: var(--ok); }
.pill.fail  { background: rgba(240, 106, 106, 0.12); color: var(--bad); }
.pill.stale { background: rgba(242, 179, 61, 0.12); color: var(--warn); }
.pill.busy  { background: rgba(59, 130, 246, 0.14); color: var(--accent); }

.backup {
  padding: 1rem 1.1rem;
}

.backup-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.backup-when {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.backup-facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem 1rem;
  margin-top: 0.9rem;
}

.backup-facts .k,
.backup-dest .k {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.backup-facts .v {
  font-variant-numeric: tabular-nums;
}

.backup-dest {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.backup-dest code {
  font-family: var(--mono);
  font-size: 0.82rem;
  word-break: break-all;
}

.backup-msg {
  margin: 0.9rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--muted);
}

.backup-msg.fail  { background: rgba(240, 106, 106, 0.1); color: var(--bad); }
.backup-msg.warn  { background: rgba(242, 179, 61, 0.08); color: var(--warn); }
.backup-msg.stale { background: rgba(242, 179, 61, 0.1); color: var(--warn); }

.backup-notes {
  margin-top: 0.7rem;
}

@media (max-width: 720px) {
  .backup-facts { grid-template-columns: repeat(2, 1fr); }
}

/* pm2 프로세스 표 */
th.r,
td.r {
  text-align: right;
}

td.muted,
span.muted {
  color: var(--muted);
}

/* listen 중인 포트. 루프백에만 묶인 포트(외부에서 못 들어옴)는 흐리게 */
.port-tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.port-tag.local {
  color: var(--muted);
  border-style: dashed;
}
