/* 서버 모니터 — 휴대폰 우선. 720px 이하: 아래 탭 메뉴 + 표는 카드 목록. 밝은/어두운 모드. */
:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f7f8fb;
    --line: #e3e7ee;
    --line-strong: #cfd6e1;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --accent: #4f46e5;
    --accent-soft: #eef0ff;
    --ok: #16a34a;
    --ok-soft: #e8f7ee;
    --warn: #d97706;
    --warn-soft: #fff4e0;
    --crit: #dc2626;
    --crit-soft: #fdecec;
    --unkn: #94a3b8;
    --unkn-soft: #eef1f5;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
    --radius: 14px;
    --radius-sm: 10px;
    --header-h: 60px;
    --tabbar-h: 64px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0f17;
        --surface: #121826;
        --surface-2: #171f30;
        --line: #232d42;
        --line-strong: #314059;
        --text: #e8ecf3;
        --text-2: #c3cbd8;
        --muted: #8592a8;
        --accent: #8b8cff;
        --accent-soft: #1f2347;
        --ok: #34d07b;
        --ok-soft: #12301f;
        --warn: #f5b041;
        --warn-soft: #362812;
        --crit: #ff6b6b;
        --crit-soft: #3a1618;
        --unkn: #7d8aa1;
        --unkn-soft: #1d2537;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num, .mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.break { word-break: break-all; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 머리 ---------- */
.app-header {
    position: sticky; top: 0; z-index: 20;
    height: var(--header-h);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--line);
}
.app-header .inner {
    max-width: 1320px; height: 100%; margin: 0 auto; padding: 0 16px;
    display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--accent), #06b6d4); color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a {
    display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 9px;
    color: var(--muted); font-weight: 500; font-size: 14.5px;
}
.nav a svg { width: 17px; height: 17px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn {
    width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
    display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn svg { width: 17px; height: 17px; }
.user-chip { font-size: 13px; color: var(--muted); }

/* ---------- 본문 ---------- */
.page { max-width: 1320px; margin: 0 auto; padding: 20px 16px 48px; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 16.5px; margin: 0; display: flex; align-items: center; gap: 8px; }
.count-pill {
    font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
    background: var(--unkn-soft); color: var(--muted);
}
.count-pill.crit { background: var(--crit-soft); color: var(--crit); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- 전체 상태 배너 ---------- */
.overall {
    display: flex; align-items: center; gap: 16px; padding: 18px 20px;
    border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
    position: relative; overflow: hidden;
}
.overall::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--ok); }
.overall.warn::before { background: var(--warn); }
.overall.crit::before { background: var(--crit); }
.overall-icon {
    width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex: none;
    background: var(--ok-soft); color: var(--ok);
}
.overall.warn .overall-icon { background: var(--warn-soft); color: var(--warn); }
.overall.crit .overall-icon { background: var(--crit-soft); color: var(--crit); }
.overall-icon svg { width: 24px; height: 24px; }
.overall-title { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.overall-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.refresh-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; animation: pulse 2s infinite; }
.refresh-dot.off { background: var(--crit); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 12px; }
.kpi { padding: 14px 16px; }
.kpi-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.kpi.crit .kpi-value { color: var(--crit); }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.ok .kpi-value { color: var(--ok); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--unkn); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.crit { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-soft); }

/* ---------- 서버 카드 ---------- */
.servers { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.srv {
    display: flex; flex-direction: column; gap: 12px; padding: 16px;
    transition: border-color .15s, transform .15s;
}
.srv:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.srv.crit { border-color: color-mix(in srgb, var(--crit) 45%, var(--line)); background: linear-gradient(180deg, var(--crit-soft), var(--surface) 55%); }
.srv.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: linear-gradient(180deg, var(--warn-soft), var(--surface) 55%); }
.srv-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.srv-name { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.srv-ip { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.srv-role { font-size: 13px; color: var(--text-2); }
.meters { display: flex; flex-direction: column; gap: 8px; }
.meter { display: grid; grid-template-columns: 48px 1fr 44px; align-items: center; gap: 8px; font-size: 12.5px; }
.meter-label { color: var(--muted); }
.meter-track { height: 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; background: var(--ok); width: 0; transition: width .4s; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.crit { background: var(--crit); }
.meter-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-2); }
.no-agent {
    font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-radius: var(--radius-sm);
    border: 1px dashed var(--line-strong); background: var(--surface-2);
}
.srv-foot { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: auto; }
.srv-foot .chips { display: flex; gap: 4px; }

/* ---------- 칩·배지 ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px;
    font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--unkn-soft); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.crit { background: var(--crit-soft); color: var(--crit); }
.badge.plain::before { display: none; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }

/* ---------- 지금 문제 ---------- */
.issues { display: flex; flex-direction: column; overflow: hidden; }
.issue { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: flex-start; }
.issue:first-child { border-top: 0; }
.issue-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--warn); flex: none; }
.issue.crit .issue-bar { background: var(--crit); }
.issue-main { flex: 1; min-width: 0; }
.issue-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.issue-msg { color: var(--text-2); font-size: 14px; margin-top: 3px; word-break: break-word; }
.issue-when { text-align: right; flex: none; font-size: 12.5px; color: var(--muted); }
.issue-when strong { display: block; color: var(--text-2); font-weight: 600; font-size: 13px; }
.all-good {
    display: flex; align-items: center; gap: 12px; padding: 18px 16px; color: var(--ok); font-weight: 600;
}
.all-good svg { width: 22px; height: 22px; }

/* ---------- 탭(세그먼트) ---------- */
.seg {
    display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 12px; overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
    border: 0; background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap;
    color: var(--muted); font-weight: 500; font-size: 14px; display: flex; gap: 6px; align-items: center;
}
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg .count-pill { font-size: 11px; padding: 0 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.search {
    flex: 1; min-width: 160px; max-width: 320px; display: flex; align-items: center; gap: 8px;
    padding: 0 12px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; height: 100%; font: inherit; color: var(--text); min-width: 0; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; user-select: none; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- 표 ---------- */
.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th {
    text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--surface-2);
    padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
table.grid td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
table.grid tr.off td { opacity: .5; }
.th-sort { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 600; color: inherit; display: inline-flex; gap: 4px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- 버튼·폼 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 14px;
    border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
    font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--line)); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.inline { display: inline; margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.form-card { padding: 20px; }
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span:first-child { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
input[type=text], input[type=number], input[type=password], select {
    height: 42px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; font: inherit;
    background: var(--surface); color: var(--text); width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
fieldset.group { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 16px; }
fieldset.group legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.danger-zone { margin-top: 16px; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.toast { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 14px; font-weight: 500; display: flex; gap: 8px; align-items: center; }
.toast.ok { background: var(--ok-soft); color: var(--ok); }
.toast.crit { background: var(--crit-soft); color: var(--crit); }

/* ---------- 서버 상세 ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }
.detail-head { padding: 20px; display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.detail-head h1 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.meta { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 6px; }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.chart { padding: 14px 16px 10px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; }
.chart-title { font-size: 13px; color: var(--muted); font-weight: 600; }
.chart-now { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.chart svg { width: 100%; height: 90px; display: block; margin-top: 6px; }
.chart .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.group-title { font-size: 13px; font-weight: 700; color: var(--muted); padding: 12px 16px 6px; background: var(--surface-2); border-top: 1px solid var(--line); }
.group-title:first-child { border-top: 0; }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { font-size: 18px; margin-bottom: 4px; }
.login-card .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
.login-card form { margin-top: 20px; }
.login-card .btn { width: 100%; height: 44px; }

/* ---------- 아래 탭 메뉴(휴대폰) ---------- */
.tabbar { display: none; }

@media (max-width: 1024px) {
    .charts { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    body { font-size: 14.5px; }
    .app-header .nav { display: none; }
    .user-chip { display: none; }
    .page { padding: 14px 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
    .page-head h1 { font-size: 20px; }
    .tabbar {
        display: grid; grid-template-columns: repeat(4, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
        border-top: 1px solid var(--line);
    }
    .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; color: var(--muted); font-weight: 500; }
    .tabbar a svg { width: 22px; height: 22px; }
    .tabbar a.on { color: var(--accent); font-weight: 600; }

    .overall { padding: 14px 16px; gap: 12px; }
    .overall-icon { width: 40px; height: 40px; border-radius: 12px; }
    .overall-title { font-size: 17px; }
    .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .kpi { padding: 12px 14px; }
    .kpi-value { font-size: 24px; }
    .servers { grid-template-columns: 1fr; gap: 10px; }
    .issue { padding: 12px 14px; flex-wrap: wrap; }
    .issue-when { text-align: left; width: 100%; padding-left: 16px; }
    .issue-when strong { display: inline; margin-right: 6px; }
    .field-row { grid-template-columns: 1fr; }
    .search { max-width: none; }

    /* 표 → 카드 목록 */
    table.grid.stack thead { display: none; }
    table.grid.stack, table.grid.stack tbody, table.grid.stack tr, table.grid.stack td { display: block; width: 100%; }
    table.grid.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
    table.grid.stack tr:last-child { border-bottom: 0; }
    table.grid.stack tbody tr:hover td { background: none; }
    table.grid.stack td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    table.grid.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; text-align: left; flex: none; }
    table.grid.stack td.primary { display: block; text-align: left; padding-bottom: 6px; }
    table.grid.stack td.primary::before { display: none; }
    table.grid.stack td:empty { display: none; }
    table.grid.stack td[data-label=""]:not(.primary) { justify-content: flex-end; padding-top: 8px; }
}

/* 긴 글자(예외 메시지·Jenkins 경로·말줄임)가 칸을 밀어 가로로 넘치지 않게 */
html, body { overflow-x: hidden; }
.servers > *, .kpis > *, .charts > *, .overall > div, .issue-title, .detail-head > div { min-width: 0; }
.issue .tag, .issue-title span { white-space: normal; word-break: break-all; }
.issue-msg, .overall-sub { overflow-wrap: anywhere; }
table.grid td { overflow-wrap: anywhere; }
.memo {
    display: inline-flex; gap: 6px; align-items: flex-start; margin-top: 6px; padding: 4px 9px; border-radius: 8px;
    font-size: 12.5px; color: var(--accent); background: var(--accent-soft); text-align: left;
}
.memo::before { content: "메모"; font-weight: 700; flex: none; }

/* 알림 멈춤 창 */
.dlg { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-body { padding: 20px; margin: 0; }
.dlg-title { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.dlg-quick { display: flex; gap: 6px; flex-wrap: wrap; }
.dlg-msg { margin: 12px 0 0; }
.halt-btn { cursor: pointer; border: 0; }
button.badge.plain.halt-btn { background: var(--warn-soft); color: var(--warn); }
input[type=datetime-local] { height: 42px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; font: inherit; background: var(--surface); color: var(--text); width: 100%; }
