:root {
  --bg: #f3f5f8; --panel: #fff; --text: #111418; --muted: #5b6570; --line: #d9dee4; --line2: #eceff3;
  --accent: #1f6feb; --accent-bg: #e8f0fe; --ok: #137333; --warn: #8a5a00; --bad: #c5221f;
  --warnbg: #fff4ce; --badbg: #fde8e7; --okbg: #e3f4e8;
  --side: #14191f; --side-text: #c9d1d9; --side-muted: #7d8793; --side-on: #ffffff; --side-on-bg: #2a3440;
  --series-1: #2a78d6; --series-2: #eb6834; --grid: #e6e8eb;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1014; --panel: #161a20; --text: #e8ebee; --muted: #9aa4ae; --line: #2c333c; --line2: #222830;
    --accent: #5b9dff; --accent-bg: #1a2a42; --ok: #4cc26a; --warn: #e0a83a; --bad: #ff6b63;
    --warnbg: #3a2e08; --badbg: #3f1515; --okbg: #11301b;
    --side: #0a0d10; --side-on-bg: #1f2a36; --series-1: #3987e5; --series-2: #d95926; --grid: #2b323b; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.6 -apple-system, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }

/* ---- 레이아웃: 좌측 메뉴 ---- */
.shell { display: flex; min-height: 100vh; }
.side { width: 248px; flex: 0 0 248px; background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto; z-index: 20; }
.side .brand { font-weight: 800; font-size: 17px; color: #fff; padding: 18px 18px 10px; letter-spacing: -.2px; }
.side nav { display: flex; flex-direction: column; padding: 0 10px; gap: 1px; }
.side .group { font-size: 11.5px; font-weight: 700; color: var(--side-muted); padding: 16px 10px 6px; letter-spacing: .3px; }
.side nav a, .side-foot a, .side-foot button.link { display: flex; align-items: center; gap: 8px; color: var(--side-text); text-decoration: none;
  padding: 11px 12px; border-radius: 8px; font-size: 15.5px; background: none; border: 0; font-family: inherit; cursor: pointer; text-align: left; width: 100%; }
.side nav a:hover, .side-foot a:hover, .side-foot button.link:hover { background: var(--side-on-bg); color: var(--side-on); }
.side nav a.on, .side-foot a.on { background: var(--accent); color: #fff; font-weight: 700; }
.side .count { margin-left: auto; background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 0 7px; line-height: 20px; }
.side-foot { margin-top: auto; padding: 12px 10px 16px; border-top: 1px solid #2a323c; }
.side-foot .who { font-size: 13px; color: var(--side-muted); padding: 4px 10px 8px; }
.side-foot .who b { color: #fff; display: block; font-size: 14px; }
body:not(.is-admin) .admin-only { display: none !important; }
.mainwrap { flex: 1; min-width: 0; }
.topbar { display: none; }
main#app { max-width: 1480px; margin: 0 auto; padding: 32px 44px 56px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 15; }
@media (max-width: 900px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 4px 0 18px rgba(0,0,0,.25); }
  body.menu-open .side { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 10; background: var(--panel);
    border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .topbar .menu { font-size: 20px; padding: 4px 10px; }
  .brand-sm { font-weight: 800; }
  main#app { padding: 14px 16px 32px; }
}

/* ---- 공통 ---- */
.pagehead { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 0 0 24px; }
.pagehead h1 { font-size: 26px; margin: 0; letter-spacing: -.3px; }
.pagehead .spacer { flex: 1; }
h2 { font-size: 19px; margin: 30px 0 12px; letter-spacing: -.2px; }
h3 { font-size: 15.5px; margin: 14px 0 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px; margin-bottom: 18px; }
.card h3 { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.stat { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 15.5px; }
th, td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
th { font-size: 13.5px; color: var(--muted); font-weight: 700; background: var(--bg); position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-bg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt { font-weight: 700; }
.amt.in { color: var(--series-1); }
.amt.out { color: var(--bad); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); margin: 1px 3px 1px 0; white-space: nowrap; color: var(--muted); }
.b-ok { background: var(--okbg); color: var(--ok); border-color: transparent; }
.b-warn { background: var(--warnbg); color: var(--warn); border-color: transparent; }
.b-bad { background: var(--badbg); color: var(--bad); border-color: transparent; }
.b-in { background: var(--series-1); color: #fff; border-color: transparent; }
.b-out { background: var(--series-2); color: #fff; border-color: transparent; }
.elapsed { font-variant-numeric: tabular-nums; font-weight: 700; }
.elapsed.w2 { color: var(--warn); }
.elapsed.w3 { color: var(--bad); }
form.inline, .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row + .row { margin-top: 8px; }
input, select, textarea { font: inherit; font-size: 15.5px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; }
input.narrow { width: 90px; }
input.mid { width: 150px; }
textarea { width: 100%; min-height: 70px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-weight: 500; font-size: 14.5px; }
button { font: inherit; font-size: 14.5px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-weight: 600; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.sm { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; margin: 6px 0; font: 13.5px/1.5 inherit; font-family: inherit; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-weight: 500; }
.note { border-left: 4px solid var(--warn); padding: 8px 12px; background: var(--warnbg); border-radius: 6px; font-size: 14px; margin: 8px 0; }
.note.bad { border-color: var(--bad); background: var(--badbg); }
.note.info { border-color: var(--accent); background: var(--accent-bg); }
.code { font: 700 30px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 3px; }
#toast { position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 520px; margin: 0 auto; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); z-index: 50; font-weight: 600; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.login label { margin-top: 10px; }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 16px; padding: 11px; font-size: 16px; }
.tablewrap { overflow-x: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }
.tabs .n { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--line); color: var(--text); font-size: 12px; text-align: center; }
.tabs .n.hot { background: var(--bad); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); padding: 7px 14px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.daypick { display: inline-flex; align-items: center; gap: 4px; }
.daypick button { padding: 7px 11px; }
.empty { padding: 26px 10px; text-align: center; color: var(--muted); }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; }
  .stat { font-size: 22px; }
  .pagehead h1 { font-size: 20px; }
  th, td { padding: 8px 6px; }
}

/* ---- 지표 타일·경고 ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; text-decoration: none; color: inherit; display: block; }
a.tile:hover { border-color: var(--accent); }
.tile .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .value { white-space: nowrap; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.3px; }
.tile .sub { font-size: 12.5px; color: var(--muted); }
.tile.in { border-top: 4px solid var(--series-1); }
.tile.out { border-top: 4px solid var(--series-2); }
.tile.hot { border-top: 4px solid var(--bad); }
.tile.hot .value { color: var(--bad); }
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.alert { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 10px; background: var(--badbg); color: var(--text); text-decoration: none; font-size: 14.5px; font-weight: 600; }
.alert.warn { background: var(--warnbg); }
.alert .ico { font-weight: 800; color: var(--bad); }
.alert.warn .ico { color: var(--warn); }
.alert .go { margin-left: auto; color: var(--muted); font-weight: 500; white-space: nowrap; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* ---- 차트 ---- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .band:hover, .chart .band.on { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.chart path.s-deposit { fill: var(--series-1); }
.chart path.s-withdrawal { fill: var(--series-2); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 0 0 6px; flex-wrap: wrap; }
.legend i, .tip i { display: inline-block; border-radius: 3px; margin-right: 5px; }
.legend i { width: 10px; height: 10px; vertical-align: -1px; }
.tip i { width: 8px; height: 8px; }
i.s-deposit { background: var(--series-1); }
i.s-withdrawal { background: var(--series-2); }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 3; }
.tip b { display: block; margin-bottom: 3px; }
.tip .r { display: flex; gap: 8px; justify-content: space-between; font-variant-numeric: tabular-nums; }
details.tableview summary, details.more summary { cursor: pointer; font-size: 13.5px; color: var(--muted); margin-top: 6px; font-weight: 600; }

/* ---- 텔레그램 메시지 ---- */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; }
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--bg); }
.msg pre { margin: 5px 0 0; border: 0; padding: 0; background: none; }
.msg .meta { display: flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.updated { font-size: 12.5px; color: var(--muted); }

/* ---- 이상 건 ---- */
.issue { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.issue .side-a, .issue .side-b { border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.issue .side-a .t, .issue .side-b .t { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.issue .val { font-size: 15.5px; font-weight: 700; }
.issue .diff { color: var(--bad); }
@media (max-width: 640px) { .issue { grid-template-columns: 1fr; } }
.notebox { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.notebox input.memo { flex: 1; min-width: 160px; }
.resolved { opacity: .62; }
.delay { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--bad); }

/* ---- 정산 ---- */
.settle-cols { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .settle-cols { grid-template-columns: 1fr; } }
input.full { flex: 1; width: 100%; }
.settle .line { display: flex; align-items: center; gap: 12px; padding: 15px 0; border-bottom: 1px solid var(--line2); flex-wrap: wrap; }
.settle .line .k { flex: 1; font-weight: 600; min-width: 140px; }
.settle .line .k .muted { font-weight: 400; }
.settle .sub { gap: 5px; margin-top: 4px; font-weight: 400; color: var(--muted); font-size: 13.5px; }
.settle .line .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; min-width: 130px; }
.settle .line.total .v { font-size: 22px; color: var(--accent); }
.settle .line.net .v { font-size: 20px; }
.settle .line input { width: 70px; text-align: right; padding: 5px 8px; }
.settle .line input.wide { width: 130px; }
.settle-head { font-size: 19px; font-weight: 800; margin-bottom: 4px; }
.spacer { flex: 1; }
main#app > h2:first-child { font-size: 26px; margin-top: 0; }
tr.on td { background: var(--accent-bg); font-weight: 700; }
a.side-a, a.side-b { color: inherit; text-decoration: none; display: block; }
a.side-a:hover, a.side-b:hover { border-color: var(--accent); }

/* ---- 업체 탭(모든 화면 맨 위) ---- */
.cotabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: -8px 0 26px; padding: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; }
.cotabs-label { font-size: 13px; font-weight: 700; color: var(--muted); padding: 0 10px 0 8px; }
.cotabs button { padding: 10px 22px; font-size: 16px; font-weight: 700; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); }
.cotabs button:hover { background: var(--accent-bg); border-color: transparent; }
.cotabs button.on { background: var(--accent); color: #fff; }
.cotabs button.all { margin-left: 6px; border-left: 1px solid var(--line); border-radius: 0 10px 10px 0; color: var(--muted); }
.cotabs button.all.on { color: #fff; border-radius: 10px; }

/* ---- 입력 화면 ---- */
.card.form label { margin-top: 12px; }
.card.form input:not([type=checkbox]), .card.form select { width: 100%; }
.card.form .msg { margin-bottom: 10px; }
.card .msg + .msg { margin-top: 10px; }
.row label.grow { flex: 1; min-width: 200px; }
label.check.big { font-size: 16px; font-weight: 700; margin-top: 16px; flex-direction: row; }
button.big { padding: 12px 28px; font-size: 16.5px; margin-top: 10px; }
.addexp { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.card.company.new { border-style: dashed; }
input.wide { min-width: 240px; }

.settle .line .addexp input { text-align: left; }
.settle .line .addexp input.exp-label { flex: 1; min-width: 240px; width: auto; }
.settle .line .addexp input.exp-amt { width: 130px; text-align: right; }
pre.tg { background: #e7f0fa; border: 0; border-radius: 12px 12px 12px 4px; padding: 12px 14px; font-size: 15px; line-height: 1.55; color: #111; margin-top: 10px; }
@media (prefers-color-scheme: dark) { pre.tg { background: #2b3a4d; color: #e8ebee; } }

.card.fmt { margin-bottom: 18px; }
.fmt-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; margin-top: 14px; }
.fmt-body textarea { font: 15px/1.55 ui-monospace, "SF Mono", Menlo, monospace; margin: 8px 0 10px; }
.fmt-lbl { font-weight: 700; margin-bottom: 6px; }
.phs { gap: 6px; }
.fmt-body pre.tg { margin-top: 0; min-height: 120px; }
