:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --line: #e4dfd3;
  --text: #1d2230;
  --muted: #6b6f7b;
  --gold: #b8860b;
  --gold-2: #d9a52b;
  --gold-soft: #fbf1d9;
  --navy: #1c2a44;
  --ok: #16834a;
  --ok-soft: #dff3e6;
  --warn: #b25e00;
  --warn-soft: #fff0da;
  --bad: #c42b2b;
  --bad-soft: #fde4e4;
  --info: #2459b8;
  --info-soft: #e3ecfb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
a { color: var(--info); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.err { color: var(--bad); font-size: .9rem; min-height: 1em; }

/* 입력 */
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); font-weight: 600; }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; min-height: 42px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--gold); }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-2); outline-offset: 0; border-color: var(--gold-2); }

/* 버튼 */
.btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 10px; padding: 9px 16px;
  min-height: 42px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: #2a3b5c; }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { background: #fff; color: var(--bad); border-color: #efb3b3; }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
.btn.big { min-height: 54px; font-size: 1.1rem; border-radius: 12px; }
.btn.huge { min-height: 72px; font-size: 1.3rem; border-radius: 14px; width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card h3 { margin-bottom: 10px; }

/* 배지 */
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }

/* 브랜드 */
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 1.25rem; }
.brand small { color: var(--muted); }
.brand-mark { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--navy); color: var(--gold-2); font-size: 1.4rem; }
.brand-mark.sm { width: 28px; height: 28px; font-size: .9rem; border-radius: 8px; }

/* 로그인 */
.login { max-width: 380px; margin: 10vh auto; padding: 0 16px; display: flex; flex-direction: column; gap: 18px; }

/* 상단바 */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--navy); color: #fff; padding: 8px 16px; }
.topbar .tb-left, .topbar .tb-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar .ev-name { color: #d7dbe6; font-size: .9rem; }
.topbar .ev-select { width: auto; min-height: 32px; padding: 4px 8px; background: #26365a; color: #fff; border-color: #3b4c73; }
.topbar .tb-links a { color: #c9d0de; text-decoration: none; padding: 4px 8px; border-radius: 6px; font-size: .9rem; }
.topbar .tb-links a.on, .topbar .tb-links a:hover { background: #2e4068; color: #fff; }
.topbar .who { font-size: .85rem; color: #c9d0de; }
.topbar .btn.ghost { color: #c9d0de; }
.topbar .btn.ghost:hover { background: #2e4068; }

/* 관리자 레이아웃 */
.layout { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 50px); }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.side button { text-align: left; border: 0; background: transparent; font: inherit; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: var(--text); font-weight: 500; }
.side button:hover { background: var(--surface-2); }
.side button.on { background: var(--gold-soft); color: var(--gold); font-weight: 700; }
.main { padding: 20px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.main > .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { position: static; }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; position: sticky; top: 0; z-index: 10; }
  .side button { white-space: nowrap; padding: 8px 10px; }
  .main { padding: 14px; }
}

/* 통계 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat .v { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* 표 */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: var(--surface-2); font-size: .8rem; color: var(--muted); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbf7; }
tbody tr.click { cursor: pointer; }
td.wrap { white-space: normal; }
.t-right { text-align: right; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 120px; }
.toolbar input[type=search] { min-width: 220px; flex: 1; }

/* 모달 */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: min(520px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* 토스트 */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: min(420px, 92vw); }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); transition: opacity .3s; font-weight: 600; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
.toast.out { opacity: 0; }

/* 폼 그리드 */
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; font: inherit; font-weight: 600; padding: 8px 14px; cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button.on { background: var(--navy); color: #fff; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; }
.chip.on { background: var(--gold); border-color: var(--gold); color: #fff; }

.qr-box { background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); width: 220px; max-width: 100%; margin: 0 auto; }
.qr-box svg { width: 100%; height: auto; display: block; }

.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px; }
.perm-grid label { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); font-weight: 600; }
.perm-grid label small { display: block; color: var(--muted); font-weight: 400; }
.perm-grid input { flex-shrink: 0; margin-top: 2px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.feed { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.feed div { display: flex; gap: 8px; font-size: .88rem; align-items: baseline; }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { background: var(--gold-soft); border: 1px solid #efd9a3; border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.diff-from { color: var(--muted); text-decoration: line-through; }
.diff-to { color: var(--info); font-weight: 700; }
