:root {
  --green: #00ae42;
  --green-d: #008a35;
  --green-l: #e6f6ec;
  --brown: #4c412a;
  --cream: #f1e4b2;
  --cream-l: #faf5e3;
  --grey: #cbc3bb;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --line: #e7e3dc;
  --line-2: #d9d3c9;
  --ink: #23201a;
  --ink-2: #5c564b;
  --ink-3: #8f887c;
  --s1: #2a78d6;   /* 차트 시리즈 1 */
  --s2: #eb6834;   /* 차트 시리즈 2 */
  --s3: #1baf7a;   /* 차트 시리즈 3 */
  --s-muted: #b9b3a9;
  --good: #1a8f4c;
  --warn: #c98500;
  --bad: #d13b3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .05), 0 2px 8px rgba(40, 30, 10, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ───── 레이아웃 ───── */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--brown); color: #f4efe2; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--green); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; }
.brand b { display: block; font-size: 15px; letter-spacing: -.2px; }
.brand span { font-size: 11px; color: #cfc5ad; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 9px;
  background: transparent; color: #e6dfcd; cursor: pointer; text-align: left; font-size: 14px;
}
.nav-btn:hover { background: rgba(255, 255, 255, .07); }
.nav-btn.active { background: var(--green); color: #fff; font-weight: 600; }
.nav-btn .ico { width: 18px; text-align: center; opacity: .9; }
.nav-sep { height: 1px; background: rgba(255, 255, 255, .1); margin: 10px 6px; }
.side-foot { margin-top: auto; font-size: 11px; color: #a99f88; padding: 0 8px; }

.main { min-width: 0; padding: 0 28px 60px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(247, 246, 242, .94); backdrop-filter: blur(6px);
  display: flex; align-items: center; gap: 12px; padding: 16px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 20px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 20px; margin: 0 auto 0 0; letter-spacing: -.4px; }
.topbar .ctl { display: flex; align-items: center; gap: 6px; }
.topbar label { font-size: 12px; color: var(--ink-3); }

select, input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], textarea {
  border: 1px solid var(--line-2); background: #fff; border-radius: 8px; padding: 7px 10px; min-height: 36px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0, 174, 66, .12); }
textarea { width: 100%; min-height: 70px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: #fff; border-radius: 8px;
  padding: 7px 14px; min-height: 36px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-d); }
.btn.dark { background: var(--brown); border-color: var(--brown); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 28px; font-size: 12px; }
.btn.toggle.on { background: var(--brown); color: #fff; border-color: var(--brown); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 9px; padding: 2px; background: #fff; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-size: 13px; }
.seg button.on { background: var(--brown); color: #fff; font-weight: 600; }

/* ───── 카드 ───── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.card h2 { font-size: 16px; margin: 0 0 4px; letter-spacing: -.3px; }
.card h3 { font-size: 14px; margin: 0 0 8px; }
.card .desc { color: var(--ink-3); font-size: 12.5px; margin: 0 0 14px; }
.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head > div:first-child { margin-right: auto; }
.card-head .desc { margin: 2px 0 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--ink-3); display: flex; justify-content: space-between; gap: 6px; }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi.accent { background: var(--brown); color: #fff; border-color: var(--brown); }
.kpi.accent .k, .kpi.accent .s { color: #e6dcc3; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }
.kpi.accent .delta.up { color: #8fe0ad; } .kpi.accent .delta.down { color: #ffb0a6; }

/* 서브탭 */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.subtabs button { border: 0; background: transparent; padding: 10px 16px; cursor: pointer; color: var(--ink-3); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtabs button.on { color: var(--ink); border-color: var(--green); }

/* 표 */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 560px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: #f4f1ea; color: var(--ink-2); font-weight: 600; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; z-index: 1; cursor: default; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--ink); }
.tbl th.num { text-align: right; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid #f0ece5; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fbf9f3; }
.tbl tr.click { cursor: pointer; }
.tbl td.name { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl input { min-height: 30px; padding: 4px 8px; width: 96px; text-align: right; }
.tbl tfoot td { background: #faf8f2; font-weight: 600; position: sticky; bottom: 0; }

/* 배지 */
.bdg { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.bdg.new { background: #e8f1fc; color: #1d5fae; }
.bdg.re { background: #fdf0e9; color: #b4471b; }
.bdg.rec { background: var(--green); color: #fff; }
.bdg.gray { background: #f1eee8; color: var(--ink-2); }
.bdg.out { border-color: var(--line-2); color: var(--ink-2); }
.bdg.A { background: #1f4f8f; color: #fff; } .bdg.B { background: #6a9fdc; color: #fff; } .bdg.C { background: #dbe7f6; color: #1f4f8f; }
.bdg.st-운영중 { background: var(--green-l); color: #0d7a37; }
.bdg.st-오픈예정 { background: #e8f1fc; color: #1d5fae; }
.bdg.st-계약완료 { background: var(--cream-l); color: #8a6a10; border-color: var(--cream); }
.bdg.st-운영종료 { background: #f1eee8; color: var(--ink-3); }
.q-star { background: #e8f1fc; color: #1d5fae; } .q-plow { background: #fdf0e9; color: #b4471b; }
.q-puzzle { background: #e5f6ef; color: #12795a; } .q-dog { background: #f1eee8; color: var(--ink-2); }

.scorebar { display: flex; align-items: center; gap: 6px; min-width: 100px; }
.scorebar i { display: block; height: 6px; border-radius: 3px; background: var(--green); }
.scorebar .track { flex: 1; height: 6px; background: #eee9e0; border-radius: 3px; overflow: hidden; }

/* 안내 배너 */
.banner { border-radius: var(--radius); padding: 14px 18px; display: flex; gap: 14px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.banner.info { background: var(--cream-l); border: 1px solid var(--cream); }
.banner.ok { background: var(--green-l); border: 1px solid #bfe7cd; }
.banner.warn { background: #fff6e5; border: 1px solid #f4dba6; }
.banner b.big { font-size: 22px; font-variant-numeric: tabular-nums; margin-right: 2px; }
.banner .stat { padding: 0 14px; border-left: 1px solid rgba(0, 0, 0, .08); }
.banner .stat:first-of-type { border-left: 0; padding-left: 0; }

/* 업로드 */
.drop {
  border: 2px dashed var(--line-2); border-radius: 12px; padding: 22px; text-align: center; cursor: pointer; background: #fcfbf8;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.drag { border-color: var(--green); background: var(--green-l); }
.drop .t { font-weight: 600; }
.drop .f { margin-top: 8px; font-size: 12.5px; color: var(--green-d); font-weight: 600; word-break: break-all; }
.preview { margin-top: 12px; font-size: 12.5px; background: #faf8f2; border-radius: 8px; padding: 10px 12px; }
.preview .row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.step-no { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--brown); color: #fff; font-size: 12px; font-weight: 700; margin-right: 6px; }
.progress { height: 8px; background: #eee9e0; border-radius: 4px; overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; background: var(--green); width: 0; transition: width .2s; }
.log { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: #2a251a; color: #e9e2cf; border-radius: 8px; padding: 10px 12px; max-height: 200px; overflow: auto; white-space: pre-wrap; }

/* 필터 줄 */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters input.grow { width: 100%; }

/* 차트 */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.hbar { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; padding: 3px 0; }
.hbar .bar { height: 14px; background: #eee9e0; border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar .bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 사분면 카드 */
.quad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.quad > div { border-radius: 10px; padding: 12px 14px; cursor: pointer; border: 2px solid transparent; }
.quad > div.on { border-color: var(--ink); }
.quad b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.quad small { display: block; font-size: 11.5px; opacity: .85; }

/* 드로어 */
.drawer-bg { position: fixed; inset: 0; background: rgba(30, 25, 15, .35); z-index: 50; }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(720px, 100vw); background: var(--bg); z-index: 51; overflow: auto;
  box-shadow: -10px 0 30px rgba(0, 0, 0, .15); padding: 22px 24px 40px;
}
.drawer h2 { margin: 0; font-size: 19px; letter-spacing: -.4px; }
.drawer .close { position: absolute; right: 18px; top: 16px; }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kv > div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kv .k { font-size: 11.5px; color: var(--ink-3); }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* 모달 */
.modal-bg { position: fixed; inset: 0; background: rgba(30, 25, 15, .4); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 22px 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.empty { text-align: center; padding: 50px 20px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 99; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--brown); z-index: 100; }
.login .box { background: #fff; padding: 30px; border-radius: 16px; width: 320px; text-align: center; }
.login input { width: 100%; margin: 14px 0 10px; }

.setting-row { display: grid; grid-template-columns: 220px 1fr; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #f0ece5; }
.setting-row:last-child { border-bottom: 0; }
.setting-row .lab b { display: block; font-size: 13.5px; }
.setting-row .lab small { color: var(--ink-3); font-size: 12px; }
.setting-row input[type=number] { width: 110px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: #f1eee8; color: var(--ink-2); white-space: nowrap; }
.chip.on { background: var(--green-l); color: #0d7a37; }

@media (max-width: 1100px) {
  .g3, .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .brand { padding: 4px 8px; width: 100%; }
  .nav-btn { width: auto; }
  .nav-sep, .side-foot { display: none; }
  .main { padding: 0 16px 40px; }
  .g2 { grid-template-columns: 1fr; }
  .quad { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .setting-row { grid-template-columns: 1fr; }
}

.g2 .tbl td.name { max-width: 200px; }
