/* 큐림 경비·회계 — 화면 꾸밈
   - 색은 모두 :root 변수로 두고, 어두운 화면(다크 모드)은 같은 변수만 바꾼다.
   - 휴대폰(390px) 먼저, PC(1100px)는 아래 @media 에서 넓힌다. */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --card: #ffffff;
  --line: #e2e0d9;
  --ink: #1b1b1a;
  --ink-2: #55534e;
  --ink-3: #8a877f;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --yellow: #fff27a;         /* 세금계산서 미발행 (엑셀 노란색과 같은 뜻) */
  --yellow-ink: #5c4d00;
  --late: #c62828;           /* 발행 기한 지남 */
  --late-bg: #fdecea;
  --good: #1b7a3a;
  --good-bg: #e7f5ec;
  --head: #002060;           /* 엑셀 머리줄 남색 */
  /* 그래프 색 (그룹 6개, 고정 순서) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413; --card: #1e1e1d; --line: #34332f;
    --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8f8d84;
    --accent: #6ea3e8; --accent-ink: #0d1b2e;
    --yellow: #6b5d00; --yellow-ink: #fff3a6;
    --late: #ff7b72; --late-bg: #3a1b19;
    --good: #6fd38f; --good-bg: #16301f;
    --head: #24345c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --card: #1e1e1d; --line: #34332f;
  --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8f8d84;
  --accent: #6ea3e8; --accent-ink: #0d1b2e;
  --yellow: #6b5d00; --yellow-ink: #fff3a6;
  --late: #ff7b72; --late-bg: #3a1b19;
  --good: #6fd38f; --good-bg: #16301f;
  --head: #24345c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* 로그인 전 탭 숨기기 등 */
a.btn { text-decoration: none; color: inherit; display: inline-block; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  padding-bottom: 72px;           /* 휴대폰 아래 탭 자리 */
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* 머리 */
.top { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 17px; margin: 0; flex: 1; }
.save-state { font-size: 12px; color: var(--ink-3); }
.save-state.err { color: var(--late); }

/* 탭: 휴대폰은 화면 아래 고정 */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 2px; font-size: 12.5px; color: var(--ink-2); position: relative; }
.tabs button.on { color: var(--accent); font-weight: 700; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--late); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .sp, .sp { flex: 1; }
.muted { color: var(--ink-3); font-size: 13px; }
.hint { color: var(--ink-2); font-size: 13px; margin: 6px 0 0; }
.grid2 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.grid2 > * { min-width: 0; }

/* 큰 숫자 */
.hero { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.delta { font-size: 13px; color: var(--ink-2); }

/* 버튼 */
.btn, .dlg-btns button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn.primary, .dlg-btns .primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.danger { color: var(--late); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 목록 */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .sub { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.click { cursor: pointer; }

/* 상태 표 */
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 10px; font-weight: 700; white-space: nowrap; }
.tag.pending { background: var(--yellow); color: var(--yellow-ink); }
.tag.late { background: var(--late-bg); color: var(--late); }
.tag.done { background: var(--good-bg); color: var(--good); }
.tag.none { background: var(--bg); color: var(--ink-3); }

/* 칩 (거래처·메모 빠른 선택) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 5px 11px; font-size: 13.5px; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* 입력 폼 */
form label { display: block; margin: 8px 0; font-size: 13.5px; color: var(--ink-2); }
form input:not([type=radio]):not([type=checkbox]), form select, form textarea {
  display: block; width: 100%; margin-top: 3px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 16px;
}
fieldset.inv { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
fieldset.inv label { display: inline-flex; gap: 4px; margin: 4px 10px 4px 0; color: var(--ink); }
.amount-big { font-size: 22px !important; font-weight: 700; text-align: right; }

dialog { border: 0; border-radius: 14px; padding: 18px; width: min(440px, calc(100% - 24px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0 0 6px; font-size: 17px; }
.dlg-btns { display: flex; gap: 8px; margin-top: 12px; }

/* 월별 표 — 엑셀처럼 (쓰시던 엑셀 색: 노란 머리줄·회색 날짜·남색 합계, 미발행 노란 칸)
   표는 종이처럼 밝은 색 그대로 (어두운 화면에서도 엑셀과 같게) */
body.wide main { max-width: none; padding: 8px 12px; }
@media (min-width: 900px) { body.wide main { padding: 12px 20px; } }
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.month-nav strong { font-size: 17px; }
.month-nav .tot { font-size: 14px; }
label.check.small { font-size: 13px; color: var(--ink-2); margin: 0; }
.fbar { display: flex; gap: 6px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.fbar .addr { font-size: 13px; font-weight: 700; min-width: 150px; padding: 0 6px; color: var(--ink-2); white-space: nowrap; }
.fbar input { flex: 1; min-width: 120px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); font-size: 15px; }
.fbar #fbAmount { flex: 0 1 220px; font-variant-numeric: tabular-nums; }
.fbar .btn.on { background: #ffff00; color: #5c4d00; border-color: #d6c400; font-weight: 700; }
.sheet-wrap { overflow: auto; border: 1px solid #b7b7b7; background: #fff; color: #000; color-scheme: light; outline: none; }
.sheet-wrap:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", sans-serif; }
table.sheet th, table.sheet td { border-right: 1px solid #d4d4d4; border-bottom: 1px solid #d4d4d4; padding: 0 6px; height: 30px; text-align: center; white-space: nowrap; }
table.sheet thead th { position: sticky; top: 0; z-index: 3; background: #ffff00; color: #000; font-weight: 400; min-width: 96px; height: 40px; white-space: normal; line-height: 1.2; border-bottom: 2px solid #555; font-size: 12.5px; }
table.sheet thead th.corner { left: 0; z-index: 5; min-width: 76px; }
table.sheet tbody th, table.sheet tfoot th { position: sticky; left: 0; z-index: 2; background: #d9d9d9; font-weight: 400; min-width: 76px; border-right: 2px solid #555; }
table.sheet th.date.sun { color: #c00000; } table.sheet th.date.sat { color: #1f4e8c; }
table.sheet tr.today th.date { background: #c6e0b4; font-weight: 700; }
table.sheet td { min-width: 96px; cursor: cell; background: #fff; font-variant-numeric: tabular-nums; position: relative; }
table.sheet td.y { background: #ffff00; }
table.sheet td.memo::after { content: ""; position: absolute; top: 0; right: 0; border: 4px solid transparent; border-top-color: #c00000; border-right-color: #c00000; }
table.sheet td.inr { background-color: #d9ead3; }
table.sheet td.y.inr { background-color: #e8e86a; }
table.sheet { user-select: none; -webkit-user-select: none; }
.sbar { display: flex; justify-content: flex-end; gap: 18px; font-size: 13px; padding: 5px 10px; background: #f3f3f3; color: #333; border: 1px solid #b7b7b7; border-top: 0; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.sbar b { color: #000; }
table.sheet td.sel { outline: 2px solid #217346; outline-offset: -2px; z-index: 1; }
table.sheet td sup { font-size: 10px; color: #1f4e8c; margin-left: 2px; }
table.sheet .daysum { background: #f2f2f2; color: #333; min-width: 100px; }
table.sheet thead th.daysum { background: #ffff00; }
table.sheet tfoot th, table.sheet tfoot td { position: sticky; bottom: 0; z-index: 2; background: #002060; color: #fff; font-weight: 400; border-top: 2px solid #555; }
table.sheet tfoot th { left: 0; z-index: 4; }
table.sheet tfoot td.daysum { background: #002060; color: #fff; font-weight: 700; }
.cell-edit { width: 100%; min-width: 84px; height: 26px; border: 0; outline: 0; background: #fff; color: #000; text-align: right; font: inherit; font-size: 14px; padding: 0 2px; }
.cell-note { position: fixed; z-index: 70; max-width: 260px; background: #ffffe1; color: #000; border: 1px solid #8a8a5c;
  box-shadow: 2px 2px 6px rgba(0,0,0,.25); padding: 6px 8px; font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; pointer-events: none;
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif; }
.sheet-hint { font-size: 12px; margin-top: 6px; }

/* 분석 — 간단하고 깔끔하게: 숫자 4개 → 막대 → 검토 목록 */
.st-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.st-head strong { font-size: 18px; min-width: 120px; text-align: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile.warn { border-color: var(--late); }
.t-label { font-size: 12.5px; color: var(--ink-2); }
.t-val { font-size: clamp(18px, 5vw, 24px); white-space: nowrap; font-weight: 800; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; margin: 2px 0; }
.t-val small { font-size: 13px; font-weight: 600; margin-left: 2px; color: var(--ink-2); }
.t-sub { font-size: 12px; color: var(--ink-3); }
.t-sub .up { color: var(--late); } .t-sub .down { color: var(--good); }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.hbar { display: grid; grid-template-columns: minmax(96px, 132px) 1fr auto 34px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.hbar .h-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-track { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.h-fill { height: 100%; background: var(--s1); border-radius: 5px; }
.hbar.non .h-fill { background: var(--ink-3); } .hbar.non .h-name { color: var(--ink-3); }
.h-val { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.h-pct { text-align: right; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
ol.rank { margin: 0; padding-left: 22px; }
ol.rank li { display: grid; grid-template-columns: 1fr auto 38px; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
ol.rank li:first-child { border-top: 0; }
ol.rank .r-val { font-variant-numeric: tabular-nums; }
.chart .bar { cursor: pointer; } .chart .bar.dim { opacity: .35; } .chart .bar:hover { opacity: 1; }
table.plain tr.cur td { background: var(--yellow); }
.list.review li { flex-wrap: wrap; }
.list.review .r-act { display: flex; gap: 6px; align-items: center; }
.list.review .sub { white-space: normal; }
.list.review select { max-width: 160px; }
/* 거래처 × 월 표: 첫 칸(거래처) 고정, 고른 달 노랗게 */
.vm-wrap { max-height: 75vh; overflow: auto; }
table.vm { width: 100%; }
table.vm td.num, table.vm th.num { text-align: right; }
table.vm { font-size: 13px; }
table.vm th, table.vm td { white-space: nowrap; padding: 6px 8px; }
table.vm th:first-child, table.vm td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
table.vm thead th { position: sticky; top: 0; background: var(--card); z-index: 2; cursor: pointer; }
table.vm thead th:first-child { z-index: 3; cursor: default; }
table.vm .cur { background: var(--yellow); color: var(--yellow-ink); }
table.vm tfoot td { font-weight: 700; border-top: 2px solid var(--line); position: sticky; bottom: 0; background: var(--bg); }
table.vm tfoot td.cur { background: var(--yellow); }
/* 분석(예전) */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.tip { position: fixed; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.15); z-index: 50; min-width: 170px; }
.tip .r { display: flex; gap: 10px; justify-content: space-between; }
table.plain { border-collapse: collapse; width: 100%; font-size: 13px; }
table.plain th, table.plain td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; }
table.plain th { color: var(--ink-2); font-weight: 600; }
.scroll-x { overflow-x: auto; }

/* 진행 막대 (그룹별 이번 달) */
.bar-row { display: grid; grid-template-columns: 96px 1fr 92px; gap: 8px; align-items: center; font-size: 13px; margin: 5px 0; }
.bar-row .track { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 5px; }

.auth { max-width: 420px; margin: 24px auto; }
.auth .card { padding: 22px 20px; }
.auth h2 { font-size: 18px; }
.auth-err { color: var(--late); background: var(--late-bg); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.btn.wide { width: 100%; padding: 11px; font-size: 16px; margin-top: 6px; }
.otp-input { font-size: 28px !important; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
label.check { display: flex; gap: 6px; align-items: center; color: var(--ink); }
.steps { padding-left: 20px; font-size: 14px; color: var(--ink-2); }
.steps li { margin: 4px 0; }
.qr { width: 220px; margin: 10px auto; background: #fff; border-radius: 8px; padding: 4px; }
.qr svg { width: 100%; height: auto; display: block; }
code.secret { font-size: 13px; word-break: break-all; }
.backup-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.backup-codes code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; text-align: center; font-size: 16px; letter-spacing: 1px; }
.hx-item { border-top: 1px solid var(--line); padding: 10px 0; }
.hx-item:first-of-type { border-top: 0; }
.hx-item > .row { flex-wrap: nowrap; }
.hx-item > .row .main { flex: 1; min-width: 0; }
.hx-item .sub { font-size: 12.5px; color: var(--ink-3); }
details.hint summary { cursor: pointer; color: var(--accent); }
.hx-bar { position: sticky; bottom: 72px; z-index: 5; }
@media (min-width: 900px) { .hx-bar { bottom: 12px; } }
.chip.hx-chip { padding: 2px; border-radius: 12px; }
.chip.hx-chip .tag { font-size: 13px; padding: 4px 10px; }
.chip.hx-chip.on { background: var(--accent); border-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 20px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

.card.warn { background: var(--late-bg); color: var(--late); border-color: transparent; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.empty { text-align: center; padding: 30px 10px; }
.empty p { color: var(--ink-2); }

/* PC 화면: 탭을 위로, 카드 2열 */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; }
  .tabs button { flex: 0 0 auto; padding: 12px 18px; font-size: 14px; }
  .tabs button.on::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px; background: var(--accent); border-radius: 2px; }
  .grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .toast { bottom: 24px; }
}
