:root {
  --bg: #f7f7f5; --surface: #ffffff; --surface2: #f0f0ee; --surface3: #e7e7e3;
  --text: #1a1a18; --text2: #55534d; --muted: #8a887f; --border: #e2e1db;
  --accent: #3b6ea5; --accent-bg: #e6eef6;
  --success: #2f7d4f; --success-bg: #e3f1e8;
  --warning: #9a6a00; --warning-bg: #f6eede;
  --danger: #b03a34; --primary: #c8643c; --on-primary: #ffffff;
  --radius: 12px;
}
:root[data-theme="dark"] {
  --bg: #191917; --surface: #232320; --surface2: #2b2b27; --surface3: #35352f;
  --text: #ececE6; --text2: #b6b4ab; --muted: #86847b; --border: #34342e;
  --accent: #8fb6df; --accent-bg: #263443;
  --success: #7fc79b; --success-bg: #223229;
  --warning: #e0b25e; --warning-bg: #35301f;
  --danger: #e08a83; --primary: #d98a63; --on-primary: #1a1a18;
}
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { color-scheme: light; } }

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 480px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.loading { color: var(--muted); text-align: center; padding: 3rem 0; }

.top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .75rem; }
.top h1 { font-size: 18px; font-weight: 600; margin: 0; }
.top .sub { font-size: 12px; color: var(--muted); }

.kpis { display: flex; gap: .5rem; margin-bottom: 1rem; }
.kpi { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .7rem; }
.kpi .k { font-size: 11px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 600; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 400; }

.sec { font-size: 12px; color: var(--text2); margin: 0 0 .4rem; display: flex; justify-content: space-between; align-items: center; }
.sec .hint { color: var(--muted); font-weight: 400; }

.cards { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .7rem; cursor: pointer; }
.card.warn { border-color: var(--warning); }
.card .row1 { display: flex; justify-content: space-between; align-items: center; }
.card .nm { font-weight: 600; }
.card .cls { font-size: 11px; color: var(--muted); margin-left: .3rem; }
.card .row2 { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .3rem; font-size: 12px; color: var(--text2); }
.card .cp { color: var(--text); font-weight: 600; }

.badge { font-size: 11px; padding: .1rem .45rem; border-radius: 99px; white-space: nowrap; }
.b-accent { background: var(--accent-bg); color: var(--accent); }
.b-success { background: var(--success-bg); color: var(--success); }
.b-warning { background: var(--warning-bg); color: var(--warning); }
.b-mute { background: var(--surface3); color: var(--text2); }
.t-success { color: var(--success); }
.t-warning { color: var(--warning); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .7rem; margin-bottom: 1rem; }
.bar { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: .3rem; }
.bar .lbl { color: var(--text2); } .bar .amt { font-weight: 600; }
.track { height: 6px; background: var(--surface3); border-radius: 99px; overflow: hidden; margin-bottom: .6rem; }
.track:last-child { margin-bottom: 0; }
.fill { height: 100%; } .fill.p { background: var(--primary); } .fill.s { background: var(--success); }

.alerts { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.alert { border-radius: var(--radius); padding: .45rem .6rem; font-size: 12px; }
.alert.w { background: var(--warning-bg); color: var(--warning); }
.alert.n { background: var(--surface2); color: var(--text2); }

.queue { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .3rem .7rem; margin-bottom: 1.2rem; font-size: 12px; color: var(--text2); }
.queue .q { padding: .3rem 0; border-top: 1px solid var(--border); }
.queue .q:first-child { border-top: none; }
.queue .q b { color: var(--text); font-weight: 600; }

.actions { display: flex; gap: .5rem; position: sticky; bottom: .6rem; }
.btn { flex: 1; height: 40px; border-radius: var(--radius); font-size: 13px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; }
.btn.primary { flex: 1.4; border: none; background: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn.ghost { background: transparent; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.modal-bg[hidden] { display: none; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 1rem; max-height: 85vh; overflow-y: auto; }
@media (min-width: 520px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: 600; margin-bottom: .8rem; }
.modal-foot { display: flex; gap: .5rem; margin-top: 1rem; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.field { margin-bottom: .7rem; }
.field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: .2rem; }
.field input, .field select { width: 100%; height: 38px; padding: 0 .6rem; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface2); color: var(--text); }
.field .row { display: flex; gap: .5rem; } .field .row > * { flex: 1; }
.check { display: flex; align-items: center; gap: .5rem; }
.check input { width: auto; height: auto; }
.src { text-align: center; font-size: 11px; color: var(--muted); margin-top: 1rem; }

/* 탭바 */
.wrap { padding-bottom: 4.5rem; }
.sec .hint { cursor: pointer; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; max-width: 480px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--border); z-index: 5; }
.tabbtn { flex: 1; height: 52px; border: none; background: none; color: var(--muted); font-size: 13px; cursor: pointer; }
.tabbtn.on { color: var(--primary); font-weight: 500; box-shadow: inset 0 2px 0 var(--primary); }

/* 테이블 (루트·시나리오) */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.rt { width: 100%; border-collapse: collapse; font-size: 12px; }
table.rt th, table.rt td { padding: .35rem .5rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.rt th { color: var(--muted); font-weight: 400; background: var(--surface2); position: sticky; top: 0; }
table.rt td.r { text-align: right; } table.rt td.g { color: var(--success); }
table.rt td.nm { white-space: normal; min-width: 9rem; color: var(--text); }
table.rt tbody tr:last-child td { border-bottom: none; }
th.rec, td.rec { background: var(--accent-bg); color: var(--text); }
.pill { font-size: 11px; padding: .05rem .35rem; border-radius: 5px; background: var(--surface3); color: var(--text2); }
.pill.귀 { background: var(--accent-bg); color: var(--accent); }
.pill.유 { background: var(--success-bg); color: var(--success); }
.pill.가 { background: var(--warning-bg); color: var(--warning); }
.legend { font-size: 12px; color: var(--text2); margin: .6rem 0; display: flex; flex-wrap: wrap; gap: .1rem .8rem; }
.legend b { color: var(--text); }

/* 레이드 */
.rblock { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .7rem; margin-bottom: .5rem; }
.rhead { display: flex; justify-content: space-between; margin-bottom: .2rem; }
.rhead .nm { font-weight: 500; } .rhead .cnt { font-size: 12px; color: var(--muted); }
.raid { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; font-size: 13px; cursor: pointer; }
.raid input { width: 18px; height: 18px; } .raid.d span { color: var(--muted); text-decoration: line-through; }

.note { font-size: 11px; color: var(--muted); margin-top: .6rem; line-height: 1.5; }
.mnote { font-size: 12px; color: var(--text2); margin: 0 0 .7rem; line-height: 1.5; }
.note code, .mnote code { background: var(--surface3); padding: 0 .25rem; border-radius: 4px; font-size: 11px; }
.field textarea, .field select { width: 100%; padding: .5rem .6rem; font-size: 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface2); color: var(--text); font-family: inherit; }
.field textarea { resize: vertical; }
