:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #16202e;
  --muted: #66748a;
  --line: #e3e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eef4ff;
  --green: #0f7a4a;
  --green-soft: #dcfce7;
  --amber: #a4620a;
  --amber-soft: #fef3c7;
  --red: #b42318;
  --red-soft: #fee4e2;
  --slate: #334155;
  --slate-soft: #eef1f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -18px rgba(16, 24, 40, .28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
em { font-style: normal; color: var(--primary); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------- 공통 요소 ---------------- */
.topbar {
  background: #0d1b2e;
  color: #fff;
  padding: 13px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand strong { font-size: 16px; letter-spacing: -.2px; }
.brand em { color: #93b4ff; }
.brand small { display: block; color: #9aabc4; font-size: 11.5px; margin-top: 1px; }
.logo-badge {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #fff; font-weight: 800; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28);
}
.logo-badge.lg { width: 48px; height: 48px; font-size: 22px; border-radius: 14px; }
.logo-badge.xl { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; }
.muted-badge { background: var(--slate-soft); color: var(--muted); box-shadow: none; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 650; font-size: 13.5px; font-family: inherit;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover { border-color: #c9d3e3; background: #fbfcfe; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 9px; }
.btn.block { width: 100%; padding: 11px 14px; }
.topbar .btn { background: #1b2c45; border-color: #2b3f5c; color: #e6edf8; }
.topbar .btn:hover { background: #24395a; }
.topbar .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 650;
  background: var(--slate-soft); color: var(--slate); white-space: nowrap;
}
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.slate { background: #23364f; color: #cddcef; }
.badge.paid { background: #f3e8ff; color: #7c3aed; }

.banner { padding: 10px 14px; border-radius: 10px; font-size: 13px; }
.banner.warn { background: var(--amber-soft); color: var(--amber); border: 1px solid #f6dfa2; }
.block-banner { margin: 12px 24px 0; }

/* ---------------- 로그인 ---------------- */
.gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(900px 420px at 50% -10%, #dbe7ff 0%, rgba(219,231,255,0) 70%),
    var(--bg);
}
.gate-card {
  width: 100%; max-width: 392px; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px 26px 22px;
  box-shadow: var(--shadow);
}
.gate-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.gate-brand h1 { margin: 0; font-size: 21px; letter-spacing: -.4px; }
.gate-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.login-form { display: grid; gap: 13px; }
.login-form label, .form-grid label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 650; color: #3c4a5f; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--text); background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #9db9f6; box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}
input.readonly { background: #f7f9fc; color: var(--muted); }
textarea { resize: vertical; min-height: 46px; }
.gate-msg { margin: 0; color: var(--red); font-size: 12.5px; font-weight: 600; }
.hint { margin: 16px 0 0; color: var(--muted); font-size: 11.8px; line-height: 1.55; }
.hint code { background: #f1f4f9; padding: 1px 4px; border-radius: 4px; }

/* ---------------- 레이아웃 ---------------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 18px 20px 56px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -1px; margin-top: 3px; }
.kpi .value small { font-size: 13px; font-weight: 650; color: var(--muted); margin-left: 3px; }

.layout { display: grid; grid-template-columns: 316px minmax(0, 1fr); gap: 16px; align-items: start; }
.pane {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.list-pane { position: sticky; top: 14px; padding: 14px; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.pane-head h2 { margin: 0; font-size: 15px; letter-spacing: -.3px; }
.search-row { margin-bottom: 10px; }
.search-row input { padding: 8px 11px; font-size: 13px; }

.filter-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  font-family: inherit; cursor: pointer;
}
.chip:hover { border-color: #cfdaf0; color: var(--slate); }
.chip.active { background: var(--primary-soft); border-color: #c7d9fb; color: var(--primary-dark); }

.tenant-list { display: grid; gap: 7px; max-height: 62vh; overflow: auto; padding-right: 2px; }
.tenant-item {
  text-align: left; width: 100%; background: #fff; border: 1px solid var(--line);
  border-radius: 11px; padding: 10px 11px; cursor: pointer; font-family: inherit;
  display: grid; gap: 4px; transition: border-color .12s, background .12s;
}
.tenant-item:hover { background: #fafcff; border-color: #cfdaf0; }
.tenant-item.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.tenant-item .t-name { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.tenant-item .t-meta { color: var(--muted); font-size: 11.5px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.active { background: #16a34a; }
.dot.pending { background: #2563eb; }
.dot.paused { background: #f59e0b; }
.dot.expired { background: #dc2626; }

.btn.approve { background: #0f7a4a; border-color: #0f7a4a; color: #fff; }
.btn.approve:hover { background: #0b6238; border-color: #0b6238; }
.badge.pending { background: var(--primary-soft); color: var(--primary-dark); }

.detail-pane { padding: 18px; min-height: 60vh; }
.empty {
  display: grid; place-items: center; gap: 12px; text-align: center;
  color: var(--muted); padding: 70px 20px; font-size: 13.5px;
}
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 6px;
}
.detail-title h2 { margin: 0 0 7px; font-size: 20px; letter-spacing: -.5px; }
.detail-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-chip { background: #f1f4f9; color: #44536b; padding: 3px 7px; border-radius: 6px; font-size: 12px; }
.link { color: var(--primary); font-size: 12.5px; font-weight: 650; text-decoration: none; }
.link:hover { text-decoration: underline; }
.detail-head-right { display: flex; gap: 8px; }

.dirty-bar {
  margin: 8px 0 14px; background: var(--amber-soft); color: var(--amber);
  border: 1px solid #f6dfa2; padding: 8px 12px; border-radius: 10px; font-size: 12.5px; font-weight: 650;
}

.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 13px;
}
.card-head h3 { margin: 0; font-size: 14.5px; letter-spacing: -.3px; }
.card-head-right { display: flex; align-items: center; gap: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid label { font-weight: 650; }

/* 모드 카드 */
.mode-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mode-card {
  text-align: left; font-family: inherit; cursor: pointer;
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px;
  display: grid; gap: 5px; transition: border-color .12s, background .12s, box-shadow .12s;
}
.mode-card:hover { border-color: #c2d3f2; background: #fbfcff; }
.mode-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.mode-card .m-title { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.mode-card .m-target { font-size: 11.5px; color: var(--muted); font-weight: 650; }
.mode-card .m-desc { font-size: 12px; color: #4b5a70; line-height: 1.45; }
.mode-card .m-count { font-size: 11.5px; color: var(--primary-dark); font-weight: 700; }

/* 기능 스위치 */
.feature-groups { display: grid; gap: 16px; }
.feature-group h4 {
  margin: 0 0 8px; font-size: 12px; letter-spacing: .3px; text-transform: uppercase; color: #7b889c;
}
.feature-list { display: grid; gap: 7px; }
.feat {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; background: #fff;
  transition: background .12s, border-color .12s;
}
.feat.on { background: #fbfdff; border-color: #d5e2fa; }
.feat-text { min-width: 0; }
.feat-title { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.feat-desc { color: var(--muted); font-size: 11.8px; margin-top: 2px; }
.diff-chip { font-size: 10.5px; font-weight: 800; padding: 1px 6px; border-radius: 999px; }
.diff-chip.plus { background: var(--green-soft); color: var(--green); }
.diff-chip.minus { background: var(--red-soft); color: var(--red); }

.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #cfd8e6; border-radius: 999px;
  cursor: pointer; transition: background .16s ease;
}
.switch span::after {
  content: ""; position: absolute; width: 19px; height: 19px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .16s ease; box-shadow: 0 1px 2px rgba(0,0,0,.18);
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(19px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(37,99,235,.25); }

/* API 카드 */
.api-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.api-row input { flex: 1 1 320px; font-size: 12.5px; }
.api-preview {
  margin: 11px 0 0; background: #0e1a2b; color: #cfe0ff; border-radius: 10px;
  padding: 12px 14px; font-size: 12px; line-height: 1.5; overflow: auto; max-height: 260px; white-space: pre-wrap;
}

/* 이력 */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; max-height: 230px; overflow: auto; }
.events li {
  display: flex; gap: 10px; font-size: 12.5px; padding: 7px 0; border-bottom: 1px dashed #eef1f6;
}
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 11.5px; flex: 0 0 118px; }
.events .ev-detail { flex: 1; }
.events .ev-actor { color: var(--muted); font-size: 11.5px; }

/* 모달 */
.modal {
  position: fixed; inset: 0; background: rgba(13, 27, 46, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 520px; background: #fff; border-radius: 16px; padding: 18px 20px;
  box-shadow: 0 24px 60px -20px rgba(13,27,46,.5); max-height: 92vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #0d1b2e; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 650; z-index: 80; box-shadow: 0 12px 30px -10px rgba(0,0,0,.5);
}
.toast.err { background: #b42318; }

/* 랜딩 */
.landing { max-width: 760px; margin: 0 auto; padding: 44px 20px 70px; }
.landing-card {
  background: #fff; border: 1px solid var(--line); border-radius: 20px;
  padding: 34px 34px 30px; box-shadow: var(--shadow);
}
.landing-card h1 { margin: 14px 0 8px; font-size: 34px; letter-spacing: -1.2px; }
.landing-lead { font-size: 16px; color: #34455e; margin: 0 0 14px; font-weight: 600; }
.landing-actions { margin: 20px 0 24px; }
.landing-list { margin: 0; padding-left: 18px; color: #44536b; display: grid; gap: 8px; font-size: 13.5px; }

/* 반응형 */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .list-pane { position: static; }
  .tenant-list { max-height: 300px; }
  .mode-cards { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .wrap { padding: 14px 12px 48px; }
  .detail-pane { padding: 14px; }
  .topbar { padding: 11px 14px; }
  .landing-card { padding: 24px 20px; }
  .landing-card h1 { font-size: 27px; }
}
