:root {
  --bg: #0b0e1a;
  --panel: #121629;
  --panel-2: #171c33;
  --border: #232a47;
  --text: #e8ebf7;
  --muted: #8b93b4;
  --dim: #5b6285;
  --accent: #5b8cff;
  --accent-2: #8b5cf6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Pretendard", "Noto Sans KR", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ── 레이아웃 ───────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; color: #fff;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--dim); }

.nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 11px 13px; border: 0; background: transparent; color: var(--muted);
  border-radius: 10px; cursor: pointer; text-align: left; font-size: 14px;
}
.nav button:hover { background: var(--panel-2); color: var(--text); }
.nav button.active { background: rgba(91, 140, 255, .14); color: #cfe0ff; font-weight: 600; }
.nav .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 700;
}
.nav-icon { width: 18px; text-align: center; opacity: .9; }

.sidebar-foot { margin-top: auto; padding: 14px; }
.server-card {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px;
}
.server-card h4 { font-size: 12px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.meter { margin-bottom: 7px; }
.meter-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }
.meter-bar { height: 5px; background: #0d1122; border-radius: 999px; margin-top: 3px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 18px 26px;
  border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.topbar .spacer { flex: 1; }
.content { padding: 22px 26px 60px; }

/* ── 공통 요소 ──────────────────────────── */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: #33406b; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb4b4; border-color: #5c2b2b; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card h3 .right { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--muted); }

.grid { display: grid; gap: 16px; }
/* 그리드 자식이 내용 폭 때문에 열을 밀어내지 않도록 (파이프라인 가로 스크롤) */
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
.cols-2b { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }

.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 32px; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .delta { font-size: 12px; margin-top: 6px; color: var(--dim); }
.delta.up { color: var(--green); } .delta.down { color: var(--red); }
.kpi-icon { margin-left: auto; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--panel-2); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); }
td { padding: 12px 10px; border-bottom: 1px solid rgba(35,42,71,.6); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

.tag {
  display: inline-block; padding: 3px 9px; border-radius: 7px;
  font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted);
}
.tag.blue { background: rgba(91,140,255,.16); color: #a8c4ff; }
.tag.green { background: rgba(34,197,94,.15); color: #86efac; }
.tag.amber { background: rgba(245,158,11,.15); color: #fcd34d; }
.tag.red { background: rgba(239,68,68,.15); color: #fca5a5; }
.tag.purple { background: rgba(139,92,246,.16); color: #c4b5fd; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); }
.dot.red { background: var(--red); } .dot.gray { background: var(--dim); }

/* ── 파이프라인 ─────────────────────────── */
.pipeline { display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 4px 2px 10px; }
.pipe-step {
  min-width: 84px; padding: 12px 8px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--panel-2); text-align: center; position: relative;
}
.pipe-step.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.12); }
.pipe-step .ico { font-size: 17px; }
.pipe-step .name { font-size: 11px; color: var(--muted); margin-top: 5px; white-space: nowrap; }
.pipe-step .count {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 6px;
}
.pipe-arrow { color: var(--dim); flex-shrink: 0; }

/* ── 큐 / 로그 ──────────────────────────── */
.queue-row { display: flex; gap: 11px; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(35,42,71,.6); }
.queue-row:last-child { border-bottom: 0; }
.thumb { width: 62px; height: 36px; border-radius: 7px; object-fit: cover; background: var(--panel-2); flex-shrink: 0; }
.queue-meta { flex: 1; min-width: 0; }
.queue-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-sub { font-size: 11px; color: var(--dim); margin-top: 2px; }
.progress { width: 92px; flex-shrink: 0; }
.progress-bar { height: 5px; background: #0d1122; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }
.progress-num { font-size: 11px; color: var(--muted); text-align: right; margin-bottom: 3px; }

.log-list { max-height: 320px; overflow-y: auto; }
.log-row { display: flex; gap: 9px; padding: 7px 0; font-size: 12px; border-bottom: 1px solid rgba(35,42,71,.4); }
.log-time { color: var(--dim); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.log-msg { flex: 1; min-width: 0; }
.log-row.ERROR .log-msg { color: #fca5a5; }
.log-row.WARN .log-msg { color: #fcd34d; }

/* ── 승인 대기 카드 ─────────────────────── */
.approval-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px; }
.approval-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.approval-card .media { position: relative; aspect-ratio: 16/9; background: #0d1122; }
.approval-card .media img { width: 100%; height: 100%; object-fit: cover; }
.approval-card .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.75); font-size: 11px; padding: 1px 6px; border-radius: 5px; }
.approval-card .body { padding: 10px 11px 12px; }
.approval-card .t { font-size: 12.5px; line-height: 1.4; height: 35px; overflow: hidden; }
.approval-card .c { font-size: 11px; color: var(--dim); margin: 6px 0 9px; }
.approval-card .actions { display: flex; gap: 6px; }

/* ── 캘린더 / 차트 ──────────────────────── */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 118px; }
.cal-day.today { border-color: var(--accent); }
.cal-head { font-size: 11px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.cal-item { font-size: 10.5px; padding: 3px 5px; border-radius: 5px; margin-bottom: 4px; background: rgba(91,140,255,.16); color: #b9cdff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-item.planned { background: rgba(139,92,246,.14); color: #c9b8ff; }
.cal-item.done { background: rgba(34,197,94,.14); color: #9df0bd; }
.cal-item.failed { background: rgba(239,68,68,.14); color: #fda4a4; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar { width: 100%; max-width: 26px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 5px 5px 0 0; min-height: 3px; }
.bar-label { font-size: 11px; color: var(--dim); }

.rate-list { display: flex; flex-direction: column; gap: 11px; }
.rate-row { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.rate-row .name { flex: 1; color: var(--muted); }
.rate-row .val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── 폼 / 모달 ──────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(5,7,15,.78); z-index: 90;
  display: grid; place-items: center; padding: 24px; overflow-y: auto;
}
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: min(720px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 15px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 11px; color: var(--dim); }
.field input, .field select, .field textarea {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); cursor: pointer; font-size: 12px; color: var(--muted); }
.chip.on { border-color: var(--accent); background: rgba(91,140,255,.16); color: #cfe0ff; }

/* ── 로그인 ─────────────────────────────── */
.login-back { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 100; }
.login-box { width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.login-box h2 { font-size: 19px; margin-bottom: 4px; }
.login-box p { font-size: 12px; color: var(--dim); margin-bottom: 20px; }
.login-box .field { margin-bottom: 12px; }
.login-err { color: #fca5a5; font-size: 12px; margin-top: 10px; min-height: 16px; }

.empty { color: var(--dim); font-size: 13px; padding: 22px 0; text-align: center; }
.toast {
  position: fixed; right: 22px; bottom: 22px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 11px; padding: 12px 16px;
  font-size: 13px; z-index: 200; box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.toast.err { border-color: #5c2b2b; color: #fca5a5; }

.hidden { display: none !important; }

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols-2, .cols-2b { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: 16px; }
}

/* 외부 문서/콘솔로 나가는 단계별 링크 버튼 */
.link-steps { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.link-steps .btn { text-decoration: none; display: inline-block; }
.link-hint { color: var(--dim); font-size: 11.5px; line-height: 1.7; margin-bottom: 14px; }
.link-hint a { color: var(--accent); }

/* AI 엔진 카드 */
.engine-block { border: 1px solid var(--border); border-radius: 12px; padding: 13px; margin-bottom: 12px; background: var(--panel-2); }
.engine-block h4 { font-size: 13px; font-weight: 700; margin-bottom: 9px; }
.engine-steps { color: var(--muted); font-size: 12px; line-height: 1.9; padding-left: 17px; margin-bottom: 10px; }
.engine-steps code { background: #0d1122; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.path-hint { color: var(--dim); font-size: 11px; line-height: 1.8; margin-top: 3px; }
.engine-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.engine-actions input[type="file"] { font-size: 11.5px; color: var(--muted); max-width: 210px; }
.engine-actions input[type="file"]::file-selector-button {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 5px 10px; margin-right: 8px; cursor: pointer; font-size: 11.5px;
}
.engine-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 8px; }
.engine-row .name { min-width: 92px; color: var(--muted); }
