@font-face {
  font-family: 'MBC NEW';
  src: url('fonts/MBCNEWBold.woff2') format('woff2'), url('fonts/MBCNEWBold.woff') format('woff');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Pretendard';
  src: url('fonts/Pretendard-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Pretendard';
  src: url('fonts/Pretendard-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #faf8fe;
  --surface: #ffffff;
  --surface-2: #eee8ff;
  --border: #e2d8fe;
  --text: #141414;
  --muted: #6b6b76;
  --primary: #6706d3;
  --primary-text: #ffffff;
  --danger: #d64545;
  --ok: #1f9d55;
  --warn: #b58900;
  --radius: 14px;
  --radius-sm: 8px;
  --font-body: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-brand: 'MBC NEW', 'Pretendard', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1420;
    --surface: #221a2c;
    --surface-2: #2c2237;
    --border: #3d2f4d;
    --text: #ece6f5;
    --muted: #a89fb5;
    --primary: #8f83ff;
    --primary-text: #14101c;
    --warn: #e0b23d;
  }
}

* { box-sizing: border-box; }
body { font-family: var(--font-body); }
h1, h2, h3, .brand, .app-title { font-family: var(--font-brand); letter-spacing: -0.01em; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Malgun Gothic', sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.sm { font-size: .8em; }
.empty { color: var(--muted); padding: 16px 0; }

/* ── 로그인 ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: .85em; }
.err { color: var(--danger); font-size: .85em; }

/* ── 공통 카드/버튼 ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: .9em;
  cursor: pointer;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn:disabled:hover { filter: none; }
.btn-sm { padding: 5px 10px; font-size: .82em; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }

input, select, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: .95em;
  font-family: inherit;
  width: 100%;
}
.inp-sm { padding: 5px 8px; width: auto; }
.chk-label { display: flex; align-items: center; gap: 6px; font-size: .85em; }
.chk-label input { width: auto; }

/* ── 상단바 / 탭 ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { font-weight: 700; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; font-size: .8em; color: var(--muted);
}
.notice {
  background: #fff7e0; color: #6b5200; border: 1px solid #f0d98a;
  padding: 8px 12px; font-size: .85em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
@media (prefers-color-scheme: dark) {
  .notice { background: #332c10; color: #f0d98a; border-color: #5a4c1c; }
}

.tabs {
  display: flex; overflow-x: auto; gap: 4px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: .88em; white-space: nowrap; cursor: pointer;
}
.tab.active { background: var(--primary); color: var(--primary-text); }

.tabs-toggle {
  display: none; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  font-size: 1.2em; line-height: 1; padding: 4px 6px; border-radius: var(--radius-sm);
}
.tabs-toggle:hover { background: var(--surface-2); }

.tabs-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 14;
}
.tabs-overlay.open { display: block; }

@media (max-width: 640px) {
  .tabs-toggle { display: flex; }
  .brand { font-size: .95em; }
  .tabs {
    flex-direction: column; align-items: stretch; overflow-x: visible; overflow-y: auto;
    position: fixed; top: 0; left: 0; bottom: 0; width: 240px; padding: 16px 10px;
    border-right: 1px solid var(--border); border-bottom: none; box-shadow: 4px 0 20px rgba(0,0,0,.25);
    z-index: 15; transform: translateX(-100%); transition: transform .22s ease;
  }
  .tabs.open { transform: translateX(0); }
  .tab { text-align: left; padding: 12px 14px; }
}

main { max-width: 1000px; margin: 0 auto; padding: 14px; }
.panel { display: none; }
.panel.active { display: block; }

/* ── 테이블/리스트 ── */
table { width: 100%; border-collapse: collapse; font-size: .9em; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82em; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
/* 계정 목록 테이블은 칼럼 너비를 colgroup으로 고정한다 — 안 그러면 "제품별 정원/사용자" 칸의
   내용 길이(제품 1개 vs 여러 개)에 따라 칼럼 폭이 들쭉날쭉해지고, 남는 공간이 전부 거기로 몰려서
   짧은 값이 있는 행은 배지와 버튼 사이에 큰 여백이 생긴다(2026-08-27 UI 어긋남 이슈). */
.accounts-table { table-layout: fixed; }
.accounts-table .acct-id { word-break: break-all; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
table td:first-child, table th:first-child { width: 1%; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }

.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; margin-bottom: 10px; font-size: .85em;
}
.bulk-bar span { color: var(--muted); margin-right: 4px; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75em;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip-ok { background: rgba(31,157,85,.12); color: var(--ok); border-color: rgba(31,157,85,.3); }
.chip-warn { background: rgba(214,69,69,.12); color: var(--danger); border-color: rgba(214,69,69,.3); }
.chip-btn { font: inherit; cursor: pointer; }

/* 계정 사용 현황: 초록(활성·미배정) / 노랑(활성·일부배정) / 파랑(활성·정원 다 채움) / 빨강(폐기) */
.usage-empty { background: rgba(31,157,85,.12); color: var(--ok); border-color: rgba(31,157,85,.35); }
.usage-partial { background: rgba(181,137,0,.14); color: var(--warn); border-color: rgba(181,137,0,.35); }
.usage-full { background: rgba(47,111,237,.12); color: var(--primary); border-color: rgba(47,111,237,.35); }
.usage-retired { background: rgba(214,69,69,.12); color: var(--danger); border-color: rgba(214,69,69,.35); }
.chip-btn:hover { filter: brightness(0.94); }

/* ── 대시보드 ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 4px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.stat .k { font-size: .78em; color: var(--muted); }
.stat .v { font-size: 1.5em; font-weight: 700; }
.bar-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: .85em; }
.bar-row .label { width: 140px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); }
.bar-fill.full { background: var(--danger); }
.bar-num { width: 56px; text-align: right; flex-shrink: 0; color: var(--muted); }

/* 기수 × 제품 매트릭스 — 옛 엑셀 배정 시트를 대체하는 대시보드 표. 칼럼이 많아질 수 있어
   가로 스크롤(.table-wrap)에 맡기고, 칸은 최대한 좁게 잡아 한 화면에 최대한 많이 보이게 한다. */
.matrix-table { font-size: .85em; }
.matrix-table th, .matrix-table td { padding: 6px 8px; white-space: nowrap; }
.matrix-table th:first-child, .matrix-table td:first-child { position: sticky; left: 0; background: var(--surface); text-align: left; z-index: 1; }
.matrix-table thead th { writing-mode: horizontal-tb; }
.matrix-total-row td { border-top: 2px solid var(--border); background: var(--surface-2); }
.matrix-cost-row td { color: var(--muted); font-size: .82em; }
.matrix-cost-row td:first-child { background: var(--surface-2); }

/* ── 모달 ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px;
  overflow-y: auto; z-index: 20;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 480px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.form-grid { display: flex; flex-direction: column; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .85em; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.seat-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.seat-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: .88em;
}

.combo-wrap { position: relative; }
.combo-dropdown {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 25;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 220px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.combo-group {
  position: sticky; top: 0; z-index: 1;
  padding: 6px 10px; font-size: .75em; color: var(--muted); font-weight: 700;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.combo-group:not(:first-child) { border-top: 1px solid var(--border); margin-top: 2px; }
.combo-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  color: var(--text); padding: 7px 10px 7px 18px; font-size: .88em; cursor: pointer; font-family: inherit;
}
.combo-item:hover { background: rgba(47,111,237,.1); }
.combo-item + .combo-group { margin-top: 2px; }

.user-dropdown-cell { position: relative; }
.user-dropdown {
  position: absolute; top: calc(100% + 2px); left: 0; z-index: 20; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 220px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 4px;
}
.user-dropdown-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; font-size: .85em; border-radius: var(--radius-sm); white-space: nowrap;
}
.user-dropdown-row:not(.muted):hover { background: var(--surface-2); }

.acct-center { vertical-align: middle; }
.account-products-cell { position: relative; vertical-align: middle; min-width: 200px; }
.acct-col { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.acct-id { font-weight: 600; }
.license-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.license-chips .chip { font-size: .72em; }
.product-usage-row { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; }
/* 트리형 테이블 — 제품이 여러 개인 계정만 "제품 N개 · x/y명 ▾"로 접혀 있다가,
   누르면 바로 아래에 제품별 행이 "같은 테이블의 진짜 행"으로 펼쳐진다(셀 안에 욱여넣지 않음).
   그래서 안 펼친 계정들과 행 높이·정렬이 항상 똑같이 유지된다 (2026-08-27 재설계). */
.tree-toggle { font-weight: 600; }
.product-subrow td { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.product-subrow-label { font-size: .85em; color: var(--muted); padding-left: 4px; }
.products-dropdown {
  position: absolute; top: calc(100% + 2px); left: 0; z-index: 20; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 240px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 4px;
}
.products-panel-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-size: .85em;
  border-radius: var(--radius-sm); white-space: nowrap; cursor: pointer;
}
.products-panel-row:hover { background: var(--surface-2); }
.products-panel-row input[type="checkbox"] { width: auto; flex-shrink: 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: .85em; z-index: 30;
}
.toast.bad { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
