:root {
  --bg: #f4f6f9; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e7ee;
  --primary: #2156c9; --primary-text: #fff; --head: #f0f3f8; --danger: #c62828; --ok-bg: #e7f6ec; --ok: #1b6b36;
  --err-bg: #fdecec; --hover: #f7f9fc; --bar: #9db6ea;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.top { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 20px;
  background: #1f2a44; color: #fff; }
.top a { color: #d6def0; }
.brand { font-weight: 700; font-size: 16px; color: #fff !important; }
.top .menu { display: flex; flex: 1; align-items: center; gap: 18px; flex-wrap: wrap; }
.menu-btn { display: none; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.who { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.who small { color: #aab6d3; }
main { padding: 16px 20px 40px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.card.narrow { max-width: 640px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h2 small { color: var(--muted); font-weight: normal; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input, select, textarea, button, .btn { font: inherit; font-size: 14px; color: var(--text); }
input, select, textarea { padding: 6px 8px; border: 1px solid #cfd6e2; border-radius: 6px; background: #fff; min-height: 34px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db6ea; border-color: var(--primary); }
button, .btn { display: inline-flex; align-items: center; justify-content: center; padding: 6px 14px; min-height: 34px;
  border: 1px solid #cfd6e2; border-radius: 6px; background: #fff; cursor: pointer; white-space: nowrap; }
button:hover, .btn:hover { background: var(--hover); text-decoration: none; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: #e7b4b4; }
button.link { border: 0; background: none; color: inherit; padding: 0; min-height: 0; text-decoration: underline; }
button.wide { width: 100%; }
form.inline { display: inline; }
.entry, .filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.entry .grow, .filters .grow { flex: 1 1 180px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
fieldset.cats { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }
fieldset.cats legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 3px; }
.chip { flex-direction: row; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip span { display: inline-block; padding: 6px 11px; border: 1px solid #cfd6e2; border-radius: 16px; color: var(--text); cursor: pointer; font-size: 13px; }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid #9db6ea; }
.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.mini { flex-direction: row; align-items: center; gap: 3px; font-size: 11px; }
.mini input { min-height: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--danger); }
.newbar { position: sticky; top: 0; z-index: 5; padding: 10px 14px; margin-bottom: 12px; border-radius: 8px; background: #fff7d6; border: 1px solid #f0d77a; }
.hint { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.count { margin: 12px 0 6px; color: var(--muted); }
.tablewrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: middle; }
table.grid thead th { background: var(--head); font-weight: 600; font-size: 13px; position: sticky; top: 0; white-space: nowrap; }
table.grid tfoot th { background: var(--head); }
table.grid tbody tr:hover { background: var(--hover); }
table.grid.num td, table.grid.num th { text-align: right; font-variant-numeric: tabular-nums; }
table.grid.num .l { text-align: left; }
table.grid.small td, table.grid.small th { padding: 4px 6px; font-size: 13px; }
tr.off { opacity: .5; }
.nowrap { white-space: nowrap; }
td.note { max-width: 320px; }
td.empty { text-align: center !important; color: var(--muted); padding: 30px; }
.neg { color: var(--danger); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef1f6; white-space: nowrap; }
.tA3영상 { background: #e3ecff; } .tA3 { background: #e5f4ea; } .t영상 { background: #fdf0dc; }
.tA4영상 { background: #efe6fb; } .tA4 { background: #e2f5f5; } .t기타 { background: #eee; }
input.money { width: 110px; text-align: right; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.kpis div { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpis span { display: block; color: var(--muted); font-size: 12px; }
.kpis b { font-size: 18px; font-variant-numeric: tabular-nums; }
.barcol { width: 18%; min-width: 80px; }
.bar { height: 10px; background: var(--bar); border-radius: 0 4px 4px 0; }
/* 미완료 */
.btns { display: flex; gap: 6px; }
button.pending-btn { background: #fff4e0; border-color: #f0a83c; color: #9a5a00; font-weight: 600; }
button.pending-btn:hover { background: #ffe9c2; }
.pending-card { border: 2px solid #f0a83c; background: #fffaf0; }
.pending-card h2 { color: #9a5a00; }
.pending-card table.grid thead th { background: #ffefd2; }
.pending-card table.grid tbody tr:hover { background: #fff3dd; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600;
  background: #f0a83c; color: #fff; vertical-align: middle; }
.badge.ok { background: #2e9d5b; }
tr.is-pending { background: #fff7e8; }
.actions { display: flex; gap: 4px; align-items: center; }
.btn.sm, button.done-btn { padding: 2px 10px; min-height: 28px; font-size: 13px; }
button.done-btn { background: #2e9d5b; border-color: #2e9d5b; color: #fff; }
button.done-btn:hover { filter: brightness(1.08); background: #2e9d5b; }
.flash.warn { background: #fff4e0; color: #9a5a00; }
.memo { white-space: pre-wrap; }
.memo-box { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--hover); min-height: 44px; }
h3.sub { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.entry label.full { flex: 1 1 100%; }
input[readonly], textarea[readonly] { background: #f3f5f8; color: #374151; cursor: default; }
input.ci-manager { width: 130px; font-weight: 600; }
textarea.ci-memo { resize: none; width: 100%; font-size: 13px; }
textarea.ci-memo.has-memo { background: #fffbea; border-color: #f0d77a; color: #5b4500; }
input.client-input.unknown { border-color: var(--danger); }
label small { font-weight: normal; }
/* 통계 탭 */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 2px solid var(--line); }
.tabs a { padding: 8px 18px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; }
.tabs a.on { background: var(--card); color: var(--primary); border: 1px solid var(--line); border-bottom: 2px solid var(--card); margin-bottom: -2px; }
.tabs a:hover { text-decoration: none; color: var(--primary); }
.periodbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.kpis small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pos { color: #1b6b36; }
tr.weekend td:first-child a { color: var(--danger); }
.twocol { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
.twocol .card { margin-bottom: 16px; }
.scrolly { max-height: 520px; overflow-y: auto; }
@media (max-width: 900px) { .twocol { grid-template-columns: 1fr; } }
.savebar { align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
input.money:focus { background: #fffbea; }
/* 권한 */
.permbox { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.permbox legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.permbox[hidden] { display: none; }
.entry .permbox.full { flex: 1 1 100%; }
table.permgrid th { font-size: 12px; white-space: normal; text-align: center; min-width: 64px; }
table.permgrid td.c { text-align: center; }
table.permgrid input[type=checkbox] { width: 18px; height: 18px; min-height: 0; cursor: pointer; }
ul.permhelp { columns: 2; margin-top: 10px; }
.role { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef1f6; }
.role.r-owner { background: #1f2a44; color: #fff; }
.role.r-admin { background: #e3ecff; color: #2156c9; }
tr.owner-row { background: #f6f8fd; }
button.small { font-size: 12px; }
button.sm { padding: 2px 10px; min-height: 28px; font-size: 13px; }
@media (max-width: 700px) { ul.permhelp { columns: 1; } }
/* 엑셀 가져오기 */
.warnbox { margin: 14px 0; padding: 12px 14px; border-radius: 8px; background: #fff4e0; border: 1px solid #f0a83c; color: #6b3f00; }
ul.rules, ul.checks { padding-left: 18px; margin: 6px 0 14px; }
ul.checks li { margin: 3px 0; }
ul.checks li.warn { color: #9a5a00; }
.kpis b.sm { font-size: 14px; }
table.months { width: auto; margin-bottom: 14px; }
.applyform { margin: 10px 0; }
.progress { display: flex; align-items: center; gap: 10px; }
.spinner { width: 18px; height: 18px; border: 3px solid #d6def0; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
td.memo { max-width: 360px; font-size: 13px; color: var(--muted); }
.pager { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 12px; }
.login-box { max-width: 360px; margin: 10vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.danger-zone { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
input.search { width: 100%; max-width: 300px; margin-bottom: 10px; }
@media (max-width: 700px) {
  main { padding: 10px 10px 30px; }
  .top { padding: 8px 12px; gap: 8px; }
  .entry label, .filters label { flex: 1 1 140px; }
  .entry fieldset.cats { flex: 1 1 100%; }
  .entry label.chip { flex: 0 0 auto; }
  .entry .btns { flex: 1 1 100%; }
  .entry .btns button { flex: 1; min-height: 44px; }
  .card { padding: 12px; }
}

/* ===== 접기 상자 (업무 입력, 검색·필터) ===== */
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; user-select: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { margin: 0; display: inline-flex; align-items: center; gap: 6px; }
details.fold > summary h2::before { content: '▸'; color: var(--muted); font-size: 12px; transition: transform .15s; }
details.fold[open] > summary h2::before { transform: rotate(90deg); }
details.fold[open] > summary { margin-bottom: 12px; }
details.fold .fold-hint { color: var(--muted); font-size: 12px; }
details.fold[open] .fold-hint:empty { display: none; }

/* ===== 휴대폰용 카드 목록 (PC에서는 숨김) ===== */
.mlist { display: none; }
.mcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--card);
  display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; }
.mcard.is-pending { background: #fffaf0; border-color: #f0a83c; }
.mcard .m1 { grid-column: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mcard .mclient { font-size: 15px; }
.mcard .m2 { grid-column: 1; color: #374151; font-size: 13px; }
.mcard .m3 { grid-column: 1; color: var(--muted); font-size: 13px; word-break: break-all; }
.mcard .mact { grid-column: 2; grid-row: 1 / span 3; display: flex; flex-direction: column; gap: 6px; align-items: stretch; justify-content: center; }
.mcard .mact .btn, .mcard .mact button { min-height: 36px; padding: 4px 14px; }
.mlist .empty { text-align: center; color: var(--muted); padding: 24px; }

/* ===================== 휴대폰 화면 ===================== */
@media (max-width: 700px) {
  /* iOS에서 입력칸을 누를 때 화면이 확대되지 않도록 16px */
  input, select, textarea, button, .btn { font-size: 16px; }
  label { font-size: 13px; }
  main { padding: 8px 8px 40px; }
  h2 { font-size: 16px; }

  /* 상단: 로고 + ☰ 버튼, 누르면 메뉴 펼침 */
  .top { position: sticky; top: 0; z-index: 30; flex-wrap: wrap; padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top)); }
  .brand { flex: 1; font-size: 17px; }
  .menu-btn { display: inline-flex; background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff;
    font-size: 20px; min-height: 40px; min-width: 44px; padding: 0 10px; }
  .menu-btn:hover { background: rgba(255,255,255,.1); }
  .top .menu { display: none; flex: 1 1 100%; flex-direction: column; align-items: stretch; gap: 8px; padding-top: 6px; }
  .top.open .menu { display: flex; }
  .top nav { flex-direction: column; gap: 2px; }
  .top nav a { padding: 12px 10px; font-size: 16px; }
  .who { flex-wrap: wrap; gap: 16px; padding: 10px; border-top: 1px solid rgba(255,255,255,.15); font-size: 14px; }

  /* 업무 입력: 두 칸씩 배치 */
  .entry { gap: 8px; }
  .entry > label { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .entry > label.grow, .entry > label.full { flex: 1 1 100%; }
  .entry input, .entry select { width: 100%; min-width: 0; }
  input.ci-manager { width: 100%; }
  .chip span { padding: 8px 13px; font-size: 14px; }
  .filters > label { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .filters > label.grow { flex: 1 1 100%; }
  .filters select, .filters input { width: 100%; min-width: 0; }
  .filters > button, .filters > .btn { flex: 1 1 auto; min-height: 42px; }

  /* 업무일지·미완료: 표 대신 카드 */
  .desk { display: none; }
  .mlist { display: block; }
  .pending-card .mcard { background: #fff; }

  /* 정산: 거래처마다 작은 카드 */
  table.settle-table thead { display: none; }
  table.settle-table, table.settle-table tbody { display: block; }
  table.settle-table tbody tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px;
    padding: 10px 2px; border-bottom: 1px solid var(--line); }
  table.settle-table tbody tr:hover { background: none; }
  table.settle-table td { border: 0; padding: 0; text-align: left !important; font-size: 14px; }
  table.settle-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  table.settle-table td.s-name { grid-column: 1 / -1; font-size: 15px; font-weight: 600; }
  table.settle-table td.s-etc, table.settle-table td.s-price { display: none; }
  table.settle-table td.empty { grid-column: 1 / -1; }
  table.settle-table input.money { width: 100%; }
  table.settle-table tfoot { display: block; }
  table.settle-table tfoot tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; padding: 10px 2px; }
  table.settle-table tfoot th { padding: 0; text-align: left !important; background: none; }
  table.settle-table tfoot th:nth-child(5), table.settle-table tfoot th:nth-child(6) { display: none; }
  .savebar { position: sticky; bottom: 0; background: var(--card); padding: 10px 0; border-top: 1px solid var(--line); z-index: 5; }
  .savebar .primary { flex: 1; min-height: 46px; }
  .savebar .hint { display: none; }

  /* 그 밖의 표: 글자가 한 줄로, 옆으로 밀어서 보기 (첫 칸 고정) */
  .tablewrap { -webkit-overflow-scrolling: touch; margin: 0 -4px; }
  .tablewrap table.grid th, .tablewrap table.grid td { white-space: nowrap; }
  .tablewrap table.grid td.note, .tablewrap table.grid td.memo { white-space: normal; min-width: 180px; }
  .tablewrap table.grid tbody td:first-child, .tablewrap table.grid thead th:first-child {
    position: sticky; left: 0; background: var(--card); z-index: 1; box-shadow: 1px 0 0 var(--line); }
  .tablewrap table.grid thead th:first-child { background: var(--head); z-index: 2; }
  .barcol { min-width: 60px; }

  /* 통계 */
  .tabs a { flex: 1; text-align: center; padding: 10px 6px; }
  .periodbar { justify-content: space-between; }
  .periodbar .btn { flex: 1; }
  .periodbar form { flex: 1 1 100%; order: -1; }
  .periodbar select, .periodbar input { width: 100%; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpis b { font-size: 16px; }
  .scrolly { max-height: none; }

  .pager { gap: 8px; }
  .pager a { padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; }
  .login-box { margin: 6vh auto; padding: 22px; }
  .card.narrow { max-width: none; }
}
