/* ==========================================================================
   Ansible Control UI - 공용 스타일
   ========================================================================== */
:root {
  --sidebar-bg: #1e2433;
  --sidebar-active: #2c3550;
  --sidebar-text: #aab2c8;
  --primary: #4f6ef7;
  --primary-dark: #3d58d8;
  --success: #22a06b;
  --success-bg: #e6f6ef;
  --danger: #e5484d;
  --danger-bg: #fdebec;
  --warning: #b8860b;
  --warning-bg: #fff6e0;
  --info: #2b7fd4;
  --info-bg: #e9f2fc;
  --bg: #f4f6fa;
  --card-bg: #ffffff;
  --border: #e3e7ef;
  --text: #232936;
  --text-sub: #6b7385;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 28, 50, 0.08), 0 4px 14px rgba(20, 28, 50, 0.05);
  --mono: 'Cascadia Code', 'D2Coding', Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .logo {
  padding: 22px 20px 18px;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar .logo small { display: block; font-size: 11px; font-weight: 400; color: var(--sidebar-text); margin-top: 3px; }
.sidebar nav { padding: 14px 10px; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 4px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar .side-foot { padding: 16px 20px; font-size: 11px; color: #5c6479; border-top: 1px solid rgba(255,255,255,0.07); }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 6px 0 0; color: var(--text-sub); font-size: 13px; }

/* ---------- 카드 / 통계 ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; }
.card h2 .count { color: var(--text-sub); font-weight: 500; font-size: 13px; margin-left: 6px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat .label { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--text-sub); margin-left: 4px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #eceff5;
  color: var(--text);
  transition: filter .15s, background .15s;
  font-family: inherit;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-ghost   { background: transparent; border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 5px; }

/* ---------- 배지 / 태그 ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-gray    { background: #eef0f5; color: var(--text-sub); }
.badge-running { background: var(--info-bg); color: var(--info); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.tag {
  display: inline-block;
  background: #eef1f8;
  color: #4a5268;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-family: var(--mono);
  margin: 2px 3px 2px 0;
}
.tag-host { background: var(--info-bg); color: var(--info); }
.tag-role { background: #f0ebfa; color: #7c53c9; }
.tag-file { background: var(--warning-bg); color: var(--warning); }

/* ---------- 테이블 ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: #f8fafd; }
.tbl .pb-name { font-weight: 600; font-family: var(--mono); font-size: 13px; }

/* ---------- 입력 ---------- */
.input, textarea.input, select.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.input:focus { outline: 2px solid rgba(79,110,247,0.35); border-color: var(--primary); }
.input-sm { padding: 5px 9px; font-size: 12.5px; }
label.fld { display: block; margin-bottom: 14px; }
label.fld .fld-name { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
label.fld .fld-hint { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

/* ---------- 알림 박스 ---------- */
.notice { border-radius: var(--radius); padding: 13px 16px; margin-bottom: 16px; font-size: 13.5px; line-height: 1.65; }
.notice-warning { background: var(--warning-bg); border: 1px solid #f0d9a0; color: #7a5b06; }
.notice-danger  { background: var(--danger-bg); border: 1px solid #f3bcbe; color: #a92e33; }
.notice-info    { background: var(--info-bg); border: 1px solid #bcd8f3; color: #1d5c9c; }
.notice b { font-weight: 700; }

/* ---------- 모달 ---------- */
.modal-bg {
  display: none;
  position: fixed; inset: 0;
  background: rgba(18, 23, 38, 0.55);
  z-index: 1000;
}
.modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(10,15,30,0.35);
  z-index: 1001;
  width: min(760px, 94vw);
  max-height: 88vh;
  display: none;
  flex-direction: column;
}
.modal.wide { width: min(1100px, 96vw); }
.modal.open, .modal-bg.open { display: flex; }
.modal-bg.open { display: block; }
.modal-head {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-head .x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-sub); padding: 4px 8px; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* 실행 마법사 단계 표시 */
.steps { display: flex; gap: 0; margin-bottom: 20px; }
.steps .step { flex: 1; text-align: center; font-size: 12.5px; color: var(--text-sub); position: relative; padding-top: 26px; }
.steps .step::before {
  content: attr(data-n);
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 22px; height: 22px; line-height: 22px;
  border-radius: 50%; background: #e6e9f2; color: var(--text-sub);
  font-weight: 700; font-size: 11px;
}
.steps .step.on { color: var(--primary); font-weight: 700; }
.steps .step.on::before { background: var(--primary); color: #fff; }
.steps .step.done { color: var(--success); }
.steps .step.done::before { background: var(--success); color: #fff; content: '✓'; }

/* 섹션 헤더 (모달 내) */
.sec { margin-bottom: 20px; }
.sec > .sec-title {
  font-weight: 700; font-size: 13.5px; margin-bottom: 9px;
  padding-left: 9px; border-left: 3px solid var(--primary);
  display: flex; align-items: center; gap: 6px;
}
.sec.orange > .sec-title { border-color: #f59e0b; }
.sec.green  > .sec-title { border-color: var(--success); }
.sec.purple > .sec-title { border-color: #8b5cf6; }
.sec .muted { color: var(--text-sub); font-style: italic; font-size: 13px; }

/* 서버 선택 체크박스 그리드 */
.host-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px; max-height: 220px; overflow-y: auto;
  background: #f8f9fc; border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}
.host-grid label {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12.5px;
  padding: 4px 6px; border-radius: 5px; cursor: pointer;
}
.host-grid label:hover { background: #eef1f8; }

/* 로그 뷰어 */
.log-view {
  background: #10141f; color: #7ce38b;
  padding: 14px 16px; border-radius: 8px;
  max-height: 62vh; overflow-y: auto;
  font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-all;
  line-height: 1.55;
}

/* ---------- 서버 관리 ---------- */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.group-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.group-card .g-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.group-card .g-name { font-weight: 700; font-family: var(--mono); font-size: 14px; word-break: break-all; }
.group-card .g-hosts { max-height: 190px; overflow-y: auto; margin-bottom: 10px; }
.group-card .g-host-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 8px; border-radius: 6px; font-family: var(--mono); font-size: 12.5px;
}
.group-card .g-host-row:hover { background: #f4f6fb; }
.group-card .g-host-row .dup { color: var(--danger); font-weight: 700; }
.group-card .g-host-row .extra { color: var(--text-sub); font-size: 11px; margin-left: 6px; }
.group-card .g-add { display: flex; gap: 6px; }

/* ---------- 파일 관리자 ---------- */
.fm { display: flex; gap: 18px; align-items: stretch; min-height: 70vh; }
.fm-tree {
  width: 320px; flex-shrink: 0;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; overflow-y: auto; max-height: 80vh;
}
.fm-tree ul { list-style: none; margin: 0; padding-left: 16px; }
.fm-tree > ul { padding-left: 0; }
.fm-tree li { margin: 1px 0; }
.fm-tree .node {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-family: var(--mono); word-break: break-all;
}
.fm-tree .node:hover { background: #f0f3fa; }
.fm-tree .node.sel { background: var(--primary); color: #fff; }
.fm-tree .node .ico { flex-shrink: 0; }
.fm-editor {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
.fm-editor .fm-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.fm-editor .fm-path { font-family: var(--mono); font-size: 13px; font-weight: 600; flex: 1; min-width: 200px; word-break: break-all; }
.fm-editor textarea {
  flex: 1; width: 100%; resize: none;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  padding: 12px; background: #fbfcfe; color: var(--text);
  min-height: 55vh; tab-size: 2;
}
.fm-editor textarea:focus { outline: 2px solid rgba(79,110,247,0.3); }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; display: inline-block; }

/* ---------- 토스트 ---------- */
#toast-box { position: fixed; bottom: 24px; right: 24px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #232936; color: #fff; padding: 11px 18px;
  border-radius: 9px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in .2s ease-out;
  max-width: 420px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 기타 ---------- */
.flex { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.muted { color: var(--text-sub); }
.mono { font-family: var(--mono); }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2.5px solid #d6dbe8; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--text-sub); padding: 30px 0; font-size: 13.5px; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; overflow-x: auto; padding: 8px; }
  .sidebar nav a { white-space: nowrap; }
  .fm { flex-direction: column; }
  .fm-tree { width: 100%; max-height: 300px; }
}
