:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --primary: #1f6feb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* 상단바 */
#topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
#topbar select, #companyName { flex: 1; font-weight: 700; font-size: 17px; border: 0; background: none; }
#main, main { max-width: 900px; margin: 0 auto; padding: 12px; }

/* 하단 탭 */
#tabbar { 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); }
#tabbar button { flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
#tabbar button span { font-size: 20px; }
#tabbar button.active { color: var(--primary); font-weight: 700; }

/* 공통 */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04); }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 14px; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
button.primary, button.ghost, button.danger { border-radius: 10px; padding: 11px 16px; border: 1px solid transparent; cursor: pointer; }
button.primary { background: var(--primary); color: #fff; font-weight: 700; }
button.ghost { background: var(--card); border-color: var(--line); }
button.danger { background: #fff; border-color: var(--bad); color: var(--bad); }
button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .5; }
.full { width: 100%; }

/* 폼 */
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 42px; }
textarea { min-height: 70px; resize: vertical; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 10px; }
.checks label { display: flex; align-items: center; gap: 6px; }
.checks input { width: 20px; height: 20px; }
.sticky-actions { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 10px 0; display: flex; gap: 8px; }

/* 목록 */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.filters .wide { grid-column: 1 / -1; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-size: 13px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.item { display: block; cursor: pointer; }
.item .top { display: flex; justify-content: space-between; gap: 8px; }
.item .client { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #eef2f7; color: #374151; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.totals div { background: var(--card); border-radius: 10px; padding: 8px 10px; }
.totals b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.totals span { font-size: 11px; color: var(--muted); }

/* 검증 표시 */
.check-box { border-radius: 10px; padding: 10px 12px; margin: 6px 0 12px; font-size: 14px; }
.check-box.ok { background: #dcfce7; color: #166534; }
.check-box.bad { background: #fee2e2; color: #991b1b; }

/* 표 */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--card); }
th, td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f9fafb; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td input.num { min-height: 32px; padding: 4px 6px; width: 110px; }
tr.total td { font-weight: 700; background: #f9fafb; }

/* 로그인 */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: 14px; max-width: 90vw; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

@media (min-width: 700px) {
  .filters { grid-template-columns: repeat(4, 1fr); }
  .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
}
