:root {
    --bg: #0f172a; --bg2: #111a2e; --panel: #172033; --panel2: #1e293b; --border: #263248;
    --text: #e2e8f0; --muted: #8b9bb4; --primary: #3b82f6; --primary2: #2563eb;
    --green: #22c55e; --red: #ef4444; --yellow: #f59e0b; --purple: #a78bfa; --cyan: #22d3ee;
    --radius: 10px; --shadow: 0 6px 20px rgba(0,0,0,.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
code { background: #0b1220; padding: 1px 6px; border-radius: 4px; font-size: 12px; }
b { font-weight: 600; }

/* ---------- 버튼/입력 ---------- */
.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; background: var(--panel2); color: var(--text); transition: .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--green); color: #052e16; }
.btn-danger { background: var(--red); color: #fff; }
.btn-warning { background: var(--yellow); color: #1c1917; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; }
input, select, textarea { background: #0b1220; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input[type=checkbox] { width: auto; }
.input-sm { padding: 5px 8px; font-size: 12px; width: auto; min-width: 120px; }
label { display: block; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.help { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ---------- 로그인 ---------- */
.login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 20% 0%, #1e3a8a55, transparent), var(--bg); z-index: 100; padding: 16px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-logo { font-size: 44px; text-align: center; }
.login-box h1 { font-size: 22px; text-align: center; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.login-error { color: var(--red); font-size: 12px; min-height: 16px; }

/* ---------- 상단바 ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 11px; }
.top-summary { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.chip { background: var(--panel2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip.ok { border-color: #166534; }
.chip.bad { border-color: #7f1d1d; background: #3b0d0d; }
.chip.warn { border-color: #78350f; }
.top-right { display: flex; align-items: center; gap: 12px; }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); display: inline-block; box-shadow: 0 0 0 0 rgba(34,197,94,.6); }
.conn-dot.on { background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.user-menu { position: relative; }
.role-chip { background: var(--primary); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 10px; margin-left: 4px; }
.dropdown { display: none; position: absolute; right: 0; top: 110%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); min-width: 160px; z-index: 30; overflow: hidden; }
.dropdown.show { display: block; }
.dropdown button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 10px 14px; cursor: pointer; font-size: 13px; }
.dropdown button:hover { background: var(--panel2); }

/* ---------- 탭 ---------- */
.tabs { display: flex; gap: 4px; padding: 8px 20px 0; background: var(--bg2); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-badge { background: var(--red); color: #fff; border-radius: 10px; font-size: 10px; padding: 1px 6px; margin-left: 4px; }
main { padding: 16px 20px 40px; flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- 패널 ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-header h2 { font-size: 15px; }
.panel-body { padding: 14px 16px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--bg2); position: sticky; top: 0; }
.table tbody tr:hover { background: #1a2438; }
.table td.wrap { white-space: normal; }
.th-actions { text-align: right; }
.td-actions { text-align: right; }
.td-actions .btn { margin-left: 4px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- 서버 카드 ---------- */
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 16px; }
.server-card { background: var(--panel); border: 1px solid var(--border); border-left: 5px solid var(--muted); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: .15s; position: relative; }
.server-card:hover { border-color: var(--primary); }
.server-card.selected { box-shadow: 0 0 0 2px var(--primary); }
.server-card.online { border-left-color: var(--green); }
.server-card.offline { border-left-color: var(--red); }
.server-card.recovering { border-left-color: var(--yellow); }
.server-card.disabled { opacity: .55; }
.server-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.server-name { font-weight: 700; font-size: 15px; }
.server-url { color: var(--muted); font-size: 11px; }
.status-pill { border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-pill.online { background: #052e16; color: #4ade80; }
.status-pill.offline { background: #450a0a; color: #fca5a5; }
.status-pill.recovering { background: #451a03; color: #fcd34d; }
.status-pill.unknown { background: var(--panel2); color: var(--muted); }
.server-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.metric { background: var(--bg2); border-radius: 8px; padding: 8px; text-align: center; }
.metric-label { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.metric-value { font-weight: 700; font-size: 15px; }
.metric-value.warn { color: var(--yellow); }
.metric-value.bad { color: var(--red); }
.bar { height: 5px; background: #0b1220; border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.bar > i.warn { background: var(--yellow); }
.bar > i.bad { background: var(--red); }
.server-procs { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.server-procs b { color: var(--text); }
.server-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; flex-wrap: wrap; }
.server-foot .muted { font-size: 11px; }
.server-actions { display: flex; gap: 4px; }
.server-error { color: #fca5a5; font-size: 11px; margin-top: 6px; }
.server-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.server-tab { background: var(--panel2); border: 1px solid var(--border); color: var(--muted); border-radius: 20px; padding: 5px 12px; font-size: 12px; cursor: pointer; font-weight: 600; }
.server-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.server-tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.server-tab .dot.on { background: var(--green); }
.server-tab .dot.off { background: var(--red); }

/* ---------- 프로세스 테이블 ---------- */
.st { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12px; }
.st::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.st.running::before { background: var(--green); }
.st.stopped::before { background: var(--red); }
.st.manual::before { background: var(--purple); }
.st.crash::before { background: var(--yellow); animation: blink 1s infinite; }
.st.disabled::before { background: #475569; }
@keyframes blink { 50% { opacity: .3; } }
tr.disabled td { color: var(--muted); }
.badge { display: inline-block; border-radius: 10px; padding: 1px 7px; font-size: 10px; font-weight: 700; margin-left: 4px; }
.badge.warn { background: #451a03; color: #fcd34d; }
.badge.info { background: #172554; color: #93c5fd; }
.badge.purple { background: #2e1065; color: #d8b4fe; }
.proc-name { font-weight: 600; }
.proc-desc { color: var(--muted); font-size: 11px; max-width: 320px; white-space: normal; }

/* ---------- 이벤트 ---------- */
.event-list { max-height: 70vh; overflow-y: auto; }
.event { display: grid; grid-template-columns: 150px 70px 90px 1fr; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 13px; align-items: center; }
.event .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lv { border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 700; text-align: center; }
.lv.error { background: #450a0a; color: #fca5a5; }
.lv.warning { background: #451a03; color: #fcd34d; }
.lv.success { background: #052e16; color: #4ade80; }
.lv.info { background: #172554; color: #93c5fd; }
.cat { color: var(--muted); font-size: 12px; }

/* ---------- 백업 ---------- */
.backup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.progress { height: 8px; background: #0b1220; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--cyan); transition: width .3s; }
.db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; padding: 14px 16px; }
.db-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.db-card h3 { font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.db-card .kv { margin: 10px 0; }
.db-card .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.ok-text { color: var(--green); }
.bad-text { color: var(--red); }
.warn-text { color: var(--yellow); }

/* ---------- 로그 드로어 ---------- */
.log-drawer { position: fixed; right: 0; bottom: 0; width: 55vw; height: 60vh; background: #0b1220; border-left: 1px solid var(--border); border-top: 1px solid var(--border); border-top-left-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 40; }
.log-drawer.full { width: 100vw; height: 100vh; border-radius: 0; }
.log-drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); gap: 8px; flex-wrap: wrap; }
.log-content { flex: 1; overflow-y: auto; padding: 8px 12px; font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; }
.log-entry { white-space: pre-wrap; word-break: break-all; padding: 1px 0; border-left: 3px solid transparent; padding-left: 6px; }
.log-entry .ts { color: #64748b; margin-right: 6px; }
.log-entry.stderr { color: #fca5a5; border-left-color: #7f1d1d; }
.log-entry.error { color: #f87171; border-left-color: var(--red); }
.log-entry.info { color: #93c5fd; }
.log-entry .hl { background: #854d0e; color: #fff; border-radius: 2px; }
.log-loading { text-align: center; color: var(--muted); padding: 6px; }
.new-log-badge { position: absolute; bottom: 14px; right: 24px; background: var(--primary); color: #fff; padding: 6px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; box-shadow: var(--shadow); }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal.show { display: flex; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-box.large { max-width: 900px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 15px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-footer .left { margin-right: auto; }

/* ---------- 토스트 ---------- */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow); max-width: 380px; animation: slideIn .25s ease; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 반응형 ---------- */
@media (max-width: 900px) {
    .backup-grid, .settings-grid, .form-row { grid-template-columns: 1fr; }
    .log-drawer { width: 100vw; height: 70vh; }
    .event { grid-template-columns: 1fr; gap: 2px; }
    main { padding: 12px; }
    .topbar { padding: 10px 12px; }
}
