:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #171a20;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-weak: #eef0ff;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-weak: #e7f6ec;
  --warn: #b45309;
  --warn-weak: #fff4e0;
  --danger: #dc2626;
  --danger-weak: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #161920;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaf0;
    --muted: #9aa2b1;
    --accent: #8b93ff;
    --accent-hover: #a3a9ff;
    --accent-weak: #22254a;
    --on-accent: #0e1015;
    --ok: #4ade80;
    --ok-weak: #11281a;
    --warn: #fbbf24;
    --warn-weak: #2c2310;
    --danger: #f87171;
    --danger-weak: #2e1616;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  word-break: keep-all;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.boot { padding: 80px 16px; text-align: center; color: var(--muted); }

/* ---------- 레이아웃 */
.container { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .tabs-inner { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); font-size: 17px;
}
.brand-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.me { display: flex; align-items: center; gap: 8px; flex: none; }
.me-name { font-weight: 600; font-size: 14px; }
.tabs-inner { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs-inner::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 10px 12px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.count-pill {
  display: inline-block; vertical-align: middle; margin-left: 4px; padding: 1px 9px;
  border-radius: 99px; background: var(--accent-weak); color: var(--accent); font-size: 14px;
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { padding: 20px; margin-bottom: 16px; }
.section > h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.section > p { margin-bottom: 14px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }
.hint { margin-top: 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- 버튼 · 입력 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input, .field input, .field select, .field textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
.field textarea { height: auto; min-height: 150px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak);
}
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field.inline { min-width: 150px; flex: 1; }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700; background: var(--accent-weak); color: var(--accent); vertical-align: 1px;
}
.badge.me { background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-weak); color: var(--ok); margin: 0; }
.badge.warn { background: var(--warn-weak); color: var(--warn); margin: 0; }
.role-badge { padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.role-master, .role-admin { background: var(--accent-weak); color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px;
  background: var(--surface-2); font-size: 13px; font-weight: 500;
}
.chip.me { background: var(--accent-weak); color: var(--accent); font-weight: 700; }
.chip.gone { text-decoration: line-through; color: var(--muted); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filter {
  height: 34px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted);
}
.filter.active { background: var(--text); border-color: var(--text); color: var(--surface); }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.loading { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- 설정 안내 배너 */
.setup { padding: 18px 20px; margin-bottom: 20px; border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--accent-weak); }
.setup h2 { font-size: 16px; margin-bottom: 8px; }
.setup ol { margin: 0; padding-left: 20px; }
.setup li { margin: 3px 0; }
.setup li.done { color: var(--muted); text-decoration: line-through; }

/* ---------- 필드보스 */
.upcoming { padding: 6px 0; margin-bottom: 20px; }
.up-row { display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 12px; padding: 10px 18px; }
.up-row + .up-row { border-top: 1px solid var(--border); }
.up-row .when { font-variant-numeric: tabular-nums; font-weight: 600; }
.up-row .left { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 88px; text-align: right; }
.up-empty { padding: 14px 18px; color: var(--muted); font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.wait { background: var(--accent); }
.dot.soon { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-weak); }
.dot.up { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-weak); }

.boss-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.boss { padding: 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .2s; }
.boss-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.boss-state .big { font-size: 28px; font-weight: 750; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.boss-state .sub { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.boss[data-state="unknown"] .big { color: var(--muted); font-size: 22px; }
.boss[data-state="soon"] { border-color: var(--warn); }
.boss[data-state="soon"] .big { color: var(--warn); }
.boss[data-state="up"] { border-color: var(--ok); }
.boss[data-state="up"] .big { color: var(--ok); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .5s linear; }
.boss[data-state="soon"] .progress > div { background: var(--warn); }
.boss[data-state="up"] .progress > div { background: var(--ok); }
.boss-meta { font-size: 13px; color: var(--muted); min-height: 20px; margin-top: auto; }

/* ---------- 참여 기록 */
.day { font-size: 13px; color: var(--muted); font-weight: 700; margin: 22px 2px 8px; }
.day:first-child { margin-top: 0; }
.event { padding: 16px 18px; margin-bottom: 10px; }
.event-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.event-head h3 { font-size: 16px; }
.event-head .time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.event-head .count { margin-left: auto; font-weight: 700; font-size: 14px; }
.tag { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.tag-boss { background: var(--accent-weak); color: var(--accent); }
.tag-war { background: var(--danger-weak); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.event-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.actions, .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- 표 */
.table-card { overflow: hidden; margin-bottom: 16px; }
.table-tools { display: flex; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.table-tools .input { max-width: 320px; }
.table-tools.between { justify-content: space-between; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--muted);
  padding: 10px 14px; background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 14px; border-top: 1px solid var(--border); white-space: nowrap; }
.table tr.is-me td { background: color-mix(in srgb, var(--accent-weak) 55%, transparent); }
.table tr.dim td { color: var(--muted); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .strong { font-weight: 700; }
.table .nick { font-weight: 600; }
.empty-cell { text-align: center; color: var(--muted); padding: 36px 14px !important; }
.boss-table td { padding: 8px 10px; }
.boss-table .input { height: 36px; min-width: 90px; }
.add-row { padding-top: 14px; }
.add-row .input { flex: 1; min-width: 120px; }
.pad { padding: 12px 14px; }

/* ---------- 정산 */
.stats-controls { padding: 16px 18px; margin-bottom: 16px; }
.stats-controls .filters { margin-bottom: 12px; }
.stats-controls .row { margin-bottom: 10px; align-items: flex-end; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 640px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { padding: 14px 16px; }
.kpi span { display: block; font-size: 13px; color: var(--muted); }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; }
.share { position: relative; min-width: 90px; height: 22px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.share-bar { position: absolute; inset: 0 auto 0 0; background: var(--accent-weak); }
.share span { position: relative; display: block; line-height: 22px; padding: 0 6px; font-size: 13px; }

/* ---------- 로그인 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 400px; padding: 28px 24px; }
.login .brand { flex-direction: column; text-align: center; gap: 12px; margin-bottom: 24px; }
.login .brand-mark { width: 52px; height: 52px; font-size: 26px; border-radius: 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 11px; background: var(--surface-2); margin-bottom: 18px; }
.seg-btn { height: 36px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.login form { display: grid; gap: 14px; }
.login input[name="secret"] { height: 48px; font-size: 17px; letter-spacing: .04em; }

/* ---------- 모달 */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 12, 20, .5); backdrop-filter: blur(2px); }
.modal { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 4px; }
.modal-body { padding: 12px 20px; overflow-y: auto; display: grid; gap: 14px; }
.modal .form-error { padding: 0 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.modal-body p { color: var(--muted); font-size: 14px; }

.picker { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.picker-tools { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.picker-tools input { flex: 1; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); outline: none; min-width: 0; }
.picker-list { max-height: 260px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 2px; padding: 6px; }
.pick { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; cursor: pointer; font-size: 14px; min-width: 0; }
.pick:hover { background: var(--surface-2); }
.pick input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick small { color: var(--muted); margin-left: auto; font-size: 12px; white-space: nowrap; }
.pick:has(input:checked) { background: var(--accent-weak); }

.code-list { display: grid; gap: 6px; }
.code-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.code-row code { font-size: 15px; font-weight: 700; letter-spacing: .06em; }

/* ---------- 토스트 */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 100;
  max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 12px;
  background: var(--text); color: var(--surface); font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 560px) {
  .container { padding-top: 18px; }
  .me-name { display: none; }
  .brand-sub { display: none; }
  .up-row { padding: 10px 14px; gap: 10px; }
  .page-head > .btn, .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
}
