:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #e5322d;
  --brand-dark: #c4221d;
  --ok: #1a7f37;
  --ok-bg: #e7f6ec;
  --low: #b42318;
  --low-bg: #fdecea;
  --over: #1d4ed8;
  --over-bg: #e8efff;
  --off: #6b7280;
  --off-bg: #f0f1f3;
  --warn-bg: #fff7e0;
  --warn: #8a5a00;
  --info-bg: #eaf2ff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f1f2f4; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* 상단 바 */
.topbar {
  display: flex; align-items: center; gap: 28px;
  background: #16181d; color: #fff;
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.brand, .login-brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo {
  display: inline-grid; place-items: center; width: 26px; height: 18px;
  background: var(--brand); color: #fff; border-radius: 5px; font-size: 10px;
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #c9ccd3; padding: 8px 14px; border-radius: 8px; }
.topbar nav a:hover { background: #262a31; color: #fff; text-decoration: none; }
.topbar nav a.active { background: #2f343d; color: #fff; }
.who { display: flex; align-items: center; gap: 10px; color: #c9ccd3; }
.who form { margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
main.narrow { max-width: 420px; padding-top: 12vh; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
.card.empty { text-align: center; color: var(--muted); padding: 40px; }

/* 버튼 */
.btn {
  appearance: none; border: 1px solid #d0d4da; background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f6f7f9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--low); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--low-bg); }
.btn.ghost { background: transparent; color: #c9ccd3; border-color: #3a3f48; }
.btn.ghost:hover { background: #262a31; color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }

/* 폼 */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; color: #374151; }
input, select {
  font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid #d0d4da; border-radius: 8px;
  background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus { outline: 2px solid #fbd3d1; border-color: var(--brand); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.row-form form { margin: 0; }
.row-form .grow { flex: 1; min-width: 240px; }
.switch { flex-direction: row; align-items: center; gap: 8px; padding-bottom: 9px; }
.inline-form { display: flex; gap: 6px; margin: 0; }
.inline-form input { width: 130px; padding: 5px 8px; }
.w-num { width: 80px; text-align: right; }
.form-foot { display: flex; justify-content: flex-end; margin-top: 12px; }

/* 알림 */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--low-bg); color: var(--low); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.info { background: var(--info-bg); color: #1e40af; display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid #93b4f5; border-top-color: #1e40af; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 통계 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; }
.stat .value.sm { font-size: 20px; }
.stat .value small { font-size: 14px; color: var(--muted); margin-left: 3px; font-weight: 600; }
.stat .sub { color: var(--muted); font-size: 12.5px; }
.stat.alert { border-color: #f1c4bf; background: #fffafa; }
.stat.alert .value { color: var(--low); }

/* 채널 */
.channels { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); gap: 16px; }
.channels .card { margin-bottom: 0; }
.channels + .card { margin-top: 16px; }
.channel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.channel-head h2 { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.mname { font-weight: 600; }
.mtitle { color: var(--muted); font-size: 12px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mtitle.wide { max-width: 460px; }
tr.off td { opacity: .55; }
tr.low td:first-child { box-shadow: inset 3px 0 0 var(--low); }

.bar { display: inline-block; width: 70px; height: 6px; background: #eceef1; border-radius: 3px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); }
tr.low .bar span { background: var(--low); }
tr.over .bar span { background: var(--over); }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; margin-right: 4px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.low { background: var(--low-bg); color: var(--low); }
.chip.over { background: var(--over-bg); color: var(--over); }
.chip.off { background: var(--off-bg); color: var(--off); }
.chip.new { background: #fff1d6; color: #8a5a00; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.bad { color: var(--low); }
.token code { display: block; padding: 10px 12px; font-size: 13px; word-break: break-all; margin-bottom: 12px; }
pre.log {
  margin: 0; max-height: 72vh; overflow: auto; background: #16181d; color: #d8dbe0;
  padding: 14px; border-radius: 8px; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all;
}
.login-card { padding: 28px; }
.login-card .muted { margin-top: 4px; margin-bottom: 18px; }

@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 12px; overflow-x: auto; }
  .channels { grid-template-columns: 1fr; }
  main { padding: 14px; }
}

/* 기기 관리 */
.channel-head .grow, .form-foot .grow { flex: 1; }
.form-foot { gap: 8px; align-items: center; }
img.thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; display: block; background: #eceef1; }
img.thumb.lg { width: 320px; height: 180px; }
img.thumb.md { width: 128px; height: 72px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; }
.source-grid { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.source-grid .kv { flex: 1; min-width: 320px; }
.desc { white-space: pre-wrap; max-height: 140px; overflow: auto; font-size: 12.5px; color: #374151; background: #f7f8fa; padding: 8px 10px; border-radius: 6px; }
tr.current td { background: #fff8f8; }
.breadcrumb { color: var(--muted); margin-bottom: 4px; }
