:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #171a21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --chip: #eef0f4;
  --today: #fff7e6;
  --today-line: #f59e0b;
  --c0: #2563eb; --c0-bg: #e8effd;
  --c1: #059669; --c1-bg: #e3f6ee;
  --c2: #d97706; --c2-bg: #fdf0dc;
  --c3: #7c3aed; --c3-bg: #efe8fd;
  --c4: #db2777; --c4-bg: #fce7f1;
  --c5: #0891b2; --c5-bg: #e0f5fa;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141b;
    --card: #1b1f2a;
    --text: #eef0f4;
    --muted: #9aa3b2;
    --line: #2a3040;
    --accent: #3b82f6;
    --chip: #262c3a;
    --today: #2a2416;
    --today-line: #f59e0b;
    --c0: #60a5fa; --c0-bg: #1a2742;
    --c1: #34d399; --c1-bg: #142e26;
    --c2: #fbbf24; --c2-bg: #352a12;
    --c3: #a78bfa; --c3-bg: #27203f;
    --c4: #f472b6; --c4-bg: #3a1c2b;
    --c5: #22d3ee; --c5-bg: #11303a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", Pretendard, "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }

.app { max-width: 720px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); }
.splash { padding: 40vh 0; text-align: center; color: var(--muted); }

/* 상단 */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar h1 { font-size: 22px; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none;
}
.avatar.role-actor { background: var(--c0-bg); color: var(--c0); border-color: transparent; }
.avatar.role-admin { background: var(--c3-bg); color: var(--c3); border-color: transparent; }
.avatar.role-staff { background: var(--c1-bg); color: var(--c1); border-color: transparent; }

.page { padding: 4px 16px 24px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; }
.section-title .link { font-size: 13px; color: var(--accent); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.card + .card { margin-top: 10px; }
.card.today { border: 2px solid var(--today-line); background: var(--today); }
.card .pad { padding: 14px 16px; }

/* 회차 행 */
.perf-row {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.perf-row:last-child { border-bottom: 0; }
.perf-row:active { background: var(--chip); }
.perf-row.past { opacity: 0.55; }
.date-block { width: 58px; flex: none; text-align: center; line-height: 1.1; }
.date-block .d { font-size: 22px; font-weight: 800; }
.date-block .m { font-size: 12px; color: var(--muted); font-weight: 600; }
.date-block .w { font-size: 12px; font-weight: 700; margin-top: 2px; }
.date-block .w.sat { color: var(--c0); } .date-block .w.sun { color: var(--danger); }
.perf-main { flex: 1; min-width: 0; }
.perf-main .t { font-weight: 700; font-size: 15px; }
.perf-main .t small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.perf-main .cast { font-size: 12px; color: var(--muted); margin-top: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 5px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); font-weight: 600; white-space: nowrap; }
.chip.c0 { background: var(--c0-bg); color: var(--c0); } .chip.c1 { background: var(--c1-bg); color: var(--c1); }
.chip.c2 { background: var(--c2-bg); color: var(--c2); } .chip.c3 { background: var(--c3-bg); color: var(--c3); }
.chip.c4 { background: var(--c4-bg); color: var(--c4); } .chip.c5 { background: var(--c5-bg); color: var(--c5); }
.total { flex: none; text-align: right; min-width: 44px; }
.total .n { font-size: 24px; font-weight: 800; line-height: 1; }
.total .u { font-size: 11px; color: var(--muted); }
.badge-today { display: inline-block; font-size: 11px; font-weight: 800; color: #fff; background: var(--today-line); padding: 2px 8px; border-radius: 999px; margin-right: 6px; vertical-align: 2px; }

/* 오늘 카드 */
.today-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.today-head .big { font-size: 20px; font-weight: 800; }
.today-head .big small { font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 6px; }
.group { margin-top: 10px; }
.group-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; padding: 6px 0; }
.group-head .sum { color: var(--muted); font-weight: 600; }
.group-head .add { color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 8px; margin-right: -8px; }
.entry {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-top: 1px solid var(--line);
}
.entry:active { opacity: 0.7; }
.entry .name { font-weight: 700; font-size: 16px; }
.entry .note { color: var(--muted); font-size: 13px; margin-left: 6px; font-weight: 500; }
.entry .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry .meta .seat { color: var(--c2); font-weight: 600; }
.entry .cnt { margin-left: auto; font-weight: 800; font-size: 17px; white-space: nowrap; }
.entry .cnt small { font-size: 12px; font-weight: 600; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 10px 0; text-align: center; }
.empty-box { padding: 36px 16px; text-align: center; color: var(--muted); }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 12px;
  padding: 12px 18px; font-weight: 700; font-size: 16px; background: var(--chip); color: var(--text); min-height: 48px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row.end { justify-content: flex-end; }
.row.end > * { flex: none; }

/* 세그먼트 */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 auto; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  font-weight: 700; font-size: 14px; padding: 0 10px;
}
.seg button.on { border-color: transparent; }
.seg button.on.c0 { background: var(--c0-bg); color: var(--c0); } .seg button.on.c1 { background: var(--c1-bg); color: var(--c1); }
.seg button.on.c2 { background: var(--c2-bg); color: var(--c2); } .seg button.on.c3 { background: var(--c3-bg); color: var(--c3); }
.seg button.on.c4 { background: var(--c4-bg); color: var(--c4); } .seg button.on.c5 { background: var(--c5-bg); color: var(--c5); }
.seg button.on.plain { background: var(--accent); color: #fff; }

/* 매수 */
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 52px; height: 52px; border-radius: 12px; background: var(--chip); font-size: 26px; font-weight: 700; flex: none; }
.stepper input { text-align: center; font-size: 26px; font-weight: 800; padding: 6px; height: 52px; }
.quick { display: flex; gap: 6px; margin-top: 8px; }
.quick button { flex: 1; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 700; }
.quick button.on { background: var(--accent); color: #fff; border-color: transparent; }

/* 탭바 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 0 calc(6px + var(--safe-b));
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.fab-tab span.fab { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin-top: -14px; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }
.tabbar button.fab-tab span.fab svg { width: 26px; height: 26px; }

/* 시트(모달) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; border-radius: 18px 18px 0 0; overflow: auto;
  padding: 10px 16px calc(24px + var(--safe-b)); animation: up 0.2s ease-out;
}
@keyframes up { from { transform: translateY(40px); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 12px; }
.sheet h2 { font-size: 19px; margin: 0 0 4px; font-weight: 800; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.sheet-head .icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--chip); display: flex; align-items: center; justify-content: center; flex: none; }
@media (min-width: 720px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; max-height: 88vh; } }

/* 등록 화면 */
.register { padding: 12vh 24px 40px; max-width: 420px; margin: 0 auto; text-align: center; }
.register h1 { font-size: 26px; margin: 0 0 6px; }
.register p { color: var(--muted); margin: 0 0 28px; }
.name-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.name-grid button { height: 72px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); font-size: 20px; font-weight: 800; }
.name-grid button.on { border-color: var(--accent); background: var(--accent); color: #fff; }
details.admin-code { margin-top: 24px; text-align: left; }
details.admin-code summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.pending-icon { font-size: 54px; margin-bottom: 10px; }

/* 전체 보기 */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.summary .tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.summary .tile .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.summary .tile .v { font-size: 22px; font-weight: 800; }
.summary .tile.c0 .v { color: var(--c0); } .summary .tile.c1 .v { color: var(--c1); } .summary .tile.c2 .v { color: var(--c2); }
.summary .tile.c3 .v { color: var(--c3); } .summary .tile.c4 .v { color: var(--c4); } .summary .tile.c5 .v { color: var(--c5); }
.full-row { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.full-row:last-child { border-bottom: 0; }
.full-row .head { display: flex; align-items: center; gap: 10px; }
.full-row .head .no { font-weight: 800; font-size: 15px; }
.full-row .head .dt { color: var(--muted); font-size: 14px; font-weight: 600; flex: 1; }
.full-row .head .sum { font-weight: 800; }
.full-row .cat-line { display: flex; gap: 8px; margin-top: 6px; font-size: 14px; }
.full-row .cat-line .lbl { flex: none; width: 66px; font-size: 12px; font-weight: 700; padding-top: 2px; }
.full-row .cat-line .names { flex: 1; color: var(--text); word-break: keep-all; }
.full-row .cat-line .names mark { background: #fde68a; color: #111; border-radius: 3px; padding: 0 2px; }
.lbl.c0 { color: var(--c0); } .lbl.c1 { color: var(--c1); } .lbl.c2 { color: var(--c2); } .lbl.c3 { color: var(--c3); } .lbl.c4 { color: var(--c4); } .lbl.c5 { color: var(--c5); }
.search { position: relative; margin: 10px 0; }
.search input { padding-left: 40px; }
.search svg { position: absolute; left: 12px; top: 13px; width: 20px; height: 20px; color: var(--muted); }

/* 관리 */
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .desc { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip); }
.pill.pending { background: #fef3c7; color: #92400e; }
.pill.approved { background: var(--c1-bg); color: var(--c1); }
.pill.blocked { background: #fee2e2; color: #991b1b; }
.pill.closed { background: var(--chip); color: var(--muted); }
.pill.active { background: var(--c1-bg); color: var(--c1); }
.list-item select { width: auto; padding: 8px 10px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input[type="checkbox"] { width: 22px; height: 22px; margin: 0; }
.check span { flex: 1; font-weight: 600; }
.code-box { font-size: 32px; font-weight: 800; letter-spacing: 0.2em; text-align: center; padding: 10px; background: var(--chip); border-radius: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 18px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 14px; z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); animation: fade 0.2s;
}
.toast.err { background: var(--danger); color: #fff; }
