:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8ef;
  --text: #0f172a; --muted: #64748b; --primary: #2563eb; --primary-soft: #dbeafe;
  --up: #dc2626; --down: #2563eb; --danger: #dc2626; --ok: #059669;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a; --border: #1f2a40;
    --text: #e2e8f0; --muted: #94a3b8; --primary: #60a5fa; --primary-soft: #1e3a5f;
    --up: #f87171; --down: #60a5fa; --danger: #f87171; --ok: #34d399;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a; --border: #1f2a40;
  --text: #e2e8f0; --muted: #94a3b8; --primary: #60a5fa; --primary-soft: #1e3a5f;
  --up: #f87171; --down: #60a5fa; --danger: #f87171; --ok: #34d399; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 'Noto Sans KR', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); }

/* 로그인 */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 12px 0 4px; font-size: 22px; }
.auth-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px; }
.btn:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 4px 0 10px; }

/* 레이아웃 */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.userbox { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: 1.4fr 1fr 1fr 1fr; margin-bottom: 14px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi.hero .value { font-size: 30px; }
.kpi .sub { font-size: 13px; margin-top: 2px; }
.charts { grid-template-columns: 1fr 1.6fr; margin-bottom: 14px; }
.chart-box { position: relative; height: 260px; }
.legend { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .nm { flex: 1; } .legend .pct { color: var(--muted); width: 48px; text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* 표 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.inactive td { opacity: .45; }
.group-row td { background: var(--surface-2); font-weight: 600; font-size: 13px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.auto { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.err { color: var(--danger); }
.badge.share { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.owner { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.owner .av { width: 22px; height: 22px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.cat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

/* 토글 */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; cursor: pointer; transition: .15s; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }

/* 관리자 */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.admin-tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.admin-tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .t { font-weight: 500; } .setting-row .d { font-size: 13px; color: var(--muted); }
.cat-group { margin-bottom: 18px; }
.cat-group h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.cat-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; background: var(--surface); }
.cat-item.off { opacity: .55; }
.cat-item .nm { font-weight: 500; } .cat-item .ds { font-size: 12.5px; color: var(--muted); }
.cat-item .grow { flex: 1; min-width: 0; }
.cat-item input[type=color] { width: 26px; height: 26px; border: 0; padding: 0; background: none; cursor: pointer; }

/* 모달 */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; padding: 22px; border: 1px solid var(--border); }
.modal h3 { margin: 0 0 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.lookup-res { font-size: 13px; margin-top: 6px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }
.masked .money { filter: blur(7px); user-select: none; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .charts { grid-template-columns: 1fr; }
  .kpi.hero { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar-in { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .kpi .value { font-size: 20px; } .kpi.hero .value { font-size: 26px; }
  .row2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
