:root {
  --bg: #f2f5f4; --panel: #fff; --fg: #16201c; --line: #e3e9e6; --head: #f6f8f7;
  --t9: #04342c; --t8: #085041; --t6: #0f6e56; --t4: #1d9e75; --t2: #5dcaa5; --t0: #e1f5ee;
  --accent: var(--t6); --accent-dark: var(--t8);
  --muted: #66706c; --bad: #b42318; --warn: #8a4b08; --warn-soft: #fff4e0; --warn-line: #f3c983;
  --radius: 10px; --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(4, 52, 44, .05), 0 4px 14px rgba(4, 52, 44, .07);
  --shadow-md: 0 2px 4px rgba(4, 52, 44, .06), 0 10px 24px rgba(4, 52, 44, .12);
  --shadow-lg: 0 18px 40px rgba(4, 52, 44, .18);
  --band: radial-gradient(80% 120% at 100% 0%, rgba(93, 202, 165, .35), transparent 60%), linear-gradient(160deg, var(--t6), var(--t9));
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
h2[id] { scroll-margin-top: 16px; }
.icon { width: 20px; height: 20px; }

/* 머리줄 : 짙은 청록 띠 */
header.band { background: var(--band); color: #fff; position: relative; overflow: hidden; }
header.band::after { content: ""; position: absolute; right: -70px; top: -90px; width: 240px; height: 240px; border-radius: 50%; border: 34px solid rgba(255, 255, 255, .06); pointer-events: none; }
header.band.tall { padding-bottom: 64px; }
header .inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; position: relative; z-index: 1; }
header .bar { display: flex; align-items: center; gap: 10px; padding: 12px 0 4px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.brand strong { font-size: 18px; letter-spacing: -0.3px; }
.logo { width: 30px; height: 30px; flex: none; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, .15); border: 1px solid rgba(255, 255, 255, .25); color: #fff; }
.logo .icon { width: 18px; height: 18px; }
.tenant { font-size: 12px; color: #fff; background: rgba(255, 255, 255, .16); border-radius: 999px; padding: 2px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.who { margin-left: auto; color: rgba(255, 255, 255, .8); font-size: 14px; white-space: nowrap; }
header form { margin: 0; }
header nav { display: flex; gap: 2px; margin: 4px -10px 0; overflow-x: auto; scrollbar-width: none; }
header nav a { padding: 9px 10px 8px; color: rgba(255, 255, 255, .72); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; transition: color .15s; }
header nav a:hover { color: #fff; }
header nav a.on { color: #fff; font-weight: 700; border-bottom-color: var(--t2); }
.hello { font-size: 21px; margin: 14px 0 0; color: #fff; }

main { padding: 18px 16px 40px; max-width: 1100px; margin: 0 auto; }
main.lifted > :first-child { margin-top: -62px; position: relative; }
.note { background: var(--panel); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-md); color: var(--muted); }

/* 단추 */
button { padding: 8px 15px; font: inherit; cursor: pointer; border: 1px solid transparent; background: var(--t8); color: #fff; border-radius: var(--radius); transition: background .15s, box-shadow .15s, transform .1s; }
button:hover { background: var(--t9); box-shadow: 0 4px 12px rgba(4, 52, 44, .25); }
button:active { transform: translateY(1px); }
button.ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .28); padding: 5px 12px; font-size: 14px; box-shadow: none; }
button.ghost:hover { background: rgba(255, 255, 255, .22); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.actions form { margin: 0; }
button.ghost-dark { background: #fff; color: var(--t8); border-color: #bcd3ca; }
button.ghost-dark:hover { background: var(--t0); box-shadow: none; }
.notice { background: var(--t0); color: var(--t8); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 12px; }
td button { background: #fff; color: var(--t8); border-color: #bcd3ca; padding: 5px 12px; font-size: 14px; }
td button:hover { background: var(--t0); box-shadow: none; }

/* 표 */
.tbl-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin: 8px 0; }
table { width: 100%; min-width: 560px; border-collapse: collapse; table-layout: fixed; }
table.form { min-width: 0; }
table.form col.lbl { width: 200px; }
th, td { padding: 10px 14px; border-bottom: 1px solid #edf1ef; text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
tbody tr:last-child > * { border-bottom: 0; }
th { background: var(--head); font-weight: 600; color: #44504b; font-size: 14px; }
table:not(.form) tbody tr { transition: background .12s; }
table:not(.form) tbody tr:hover td { background: #f5faf8; }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #d4ddd9; border-radius: 8px; background: #fff; color: var(--fg); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--t4); box-shadow: 0 0 0 3px rgba(29, 158, 117, .18); }
button:focus-visible { outline: 2px solid var(--t2); outline-offset: 2px; }
table.form input:not([type=checkbox]), table.form select, table.form textarea { width: 100%; }
td form { margin: 0; }
.err { color: var(--bad); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 홈 요약 카드 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0 0 8px; }
.stat { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: var(--radius-lg); padding: 14px; text-decoration: none; color: var(--fg); box-shadow: var(--shadow-md); transition: transform .2s, box-shadow .2s; animation: rise .5s ease both; }
.stat:nth-child(2) { animation-delay: .06s; } .stat:nth-child(3) { animation-delay: .12s; } .stat:nth-child(4) { animation-delay: .18s; }
.stat:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(4, 52, 44, .08), 0 16px 32px rgba(4, 52, 44, .16); }
.stat .ic { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--t4), var(--t8)); box-shadow: 0 4px 10px rgba(15, 110, 86, .3); }
.stat .txt { min-width: 0; }
.stat .txt span { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b { display: block; font-size: 26px; line-height: 1.15; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.warn .ic { background: linear-gradient(135deg, #f0a53a, #b86a10); box-shadow: 0 4px 10px rgba(184, 106, 16, .3); }
.stat.warn b { color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 로그인 */
main.bare { min-height: 100vh; max-width: none; display: flex; align-items: center; justify-content: center; padding: 20px 16px;
  background: radial-gradient(60% 50% at 20% 10%, rgba(93, 202, 165, .18), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 400px; border-radius: 20px; overflow: hidden; background: var(--panel); box-shadow: var(--shadow-lg); animation: rise .5s ease both; }
.login-top { background: var(--band); color: #e1f5ee; padding: 28px 26px 64px; position: relative; overflow: hidden; }
.login-top::after { content: ""; position: absolute; right: -60px; bottom: -70px; width: 190px; height: 190px; border-radius: 50%; border: 30px solid rgba(255, 255, 255, .07); }
.login-top .logo { width: 44px; height: 44px; border-radius: 12px; }
.login-top .logo .icon { width: 24px; height: 24px; }
.login-top strong { display: block; font-size: 26px; color: #fff; margin-top: 14px; letter-spacing: -0.5px; }
.login-top span { display: block; font-size: 14px; opacity: .85; }
.login-form { margin: -40px 16px 18px; background: var(--panel); border-radius: 16px; padding: 22px 20px; box-shadow: var(--shadow-md); position: relative; }
form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #44504b; }
form.stack input { width: 100%; padding: 11px 12px; font-size: 16px; }
form.stack button { padding: 12px; font-size: 16px; font-weight: 700; margin-top: 4px; }
.login-form .err { margin: 0 0 12px; font-size: 14px; }

/* 달 고르기 · 줄 단추 · 작은 이름표 */
.period { display: flex; align-items: center; gap: 14px; margin: 0 0 12px; }
.period a { text-decoration: none; color: var(--muted); }
.period a:hover { color: var(--t6); }
.period strong { font-size: 18px; }
.row-actions { display: flex; gap: 6px; }
.row-actions form { margin: 0; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--t0); color: var(--t8); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* 수집 : 토너 막대 · 연결 코드 */
.bars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.bar { position: relative; display: block; height: 18px; border-radius: 5px; background: #eef1f0; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar b { position: relative; display: block; text-align: center; font-size: 11px; line-height: 18px; color: #1c2421; }
.c-black { background: #6b716e; } .c-cyan { background: #3fb6e0; } .c-magenta { background: #e0569b; } .c-yellow { background: #f2c94c; } .c-other { background: #9aa5a0; }
.bar i.low { box-shadow: inset 0 0 0 2px #b42318; }
.code { font-family: Consolas, monospace; font-size: 15px; word-break: break-all; padding: 14px 16px; margin: 0; user-select: all; }

/* 청구서 */
.invoice { background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 24px; }
.inv-head { display: flex; align-items: center; gap: 10px; }
.inv-head h1 { margin: 0; font-size: 26px; letter-spacing: 4px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.inv-parties div { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.inv-parties small, .inv-parties span { display: block; color: var(--muted); font-size: 13px; }
.inv-parties strong { display: block; font-size: 17px; }
.inv-total { max-width: 420px; margin-left: auto; }
.invoice .tbl-wrap { box-shadow: none; border: 1px solid var(--line); }
@media print {
  body { background: #fff; }
  header.band, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .invoice { box-shadow: none; padding: 0; }
  table { min-width: 0; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat .ic { width: 34px; height: 34px; border-radius: 10px; }
  .stat b { font-size: 22px; }
  .who { display: none; }
  header form { margin-left: auto; }
  table.form col.lbl { width: 34%; }
  table.form th, table.form td { padding: 8px 10px; }
  .inv-parties { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 홈 거래처 현황 */
.flags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag.urgent { background: #fde8e6; color: #b42318; font-weight: 600; }
.tag.info { background: #eef1f0; color: var(--muted); }
.dev { display: grid; grid-template-columns: 110px minmax(0, 1fr) 70px; align-items: center; gap: 8px; padding: 2px 0; }
.dev + .dev { border-top: 1px dashed #e3ebe8; padding-top: 4px; margin-top: 2px; }
.dev > a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .waste { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.bar b { text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; }
.dev { grid-template-columns: 100px minmax(200px, 1fr) 64px; }
td form button, .row-actions button { white-space: nowrap; }

/* 홈 달력 */
.cal { background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 14px; margin: 0 0 18px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.cal-head strong { font-size: 18px; }
.cal-head a { text-decoration: none; color: var(--t8); }
.cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th { font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; text-align: center; }
.cal-grid th.we { color: #b42318; }
.cal-grid td { padding: 2px; text-align: center; }
.cal-grid td a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 52px; border-radius: 10px; text-decoration: none; color: var(--fg); }
.cal-grid td a:hover { background: var(--t0); }
.cal-grid td.out a { color: #b8c2bf; }
.cal-grid td.today .d { background: var(--t4); color: #fff; border-radius: 999px; padding: 0 7px; }
.cal-grid td.sel a { outline: 2px solid var(--t4); background: var(--t0); }
.cal-grid .dots { font-size: 11px; line-height: 16px; min-width: 18px; border-radius: 999px; background: #f0a53a; color: #fff; padding: 0 5px; }
.day h2 { margin-top: 0; }
.vcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 0 0 12px; }
.vcard { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: var(--shadow-md); text-decoration: none; color: var(--fg); }
a.vcard:hover { transform: translateY(-2px); }
.add-visit, .search { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.add-visit select, .add-visit input, .search input { width: auto; min-width: 160px; flex: 1 1 160px; }
.clients > summary { cursor: pointer; list-style: none; }
.clients > summary h2 { display: inline-block; }
.clients > summary::before { content: '▾ '; color: var(--muted); }
.clients:not([open]) > summary::before { content: '▸ '; }
.dev .dn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 방문 카드 */
.devcard { background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 14px 16px; margin: 0 0 14px; }
.devcard h2 { margin-top: 0; }
.dev-status { display: grid; gap: 6px; margin: 0 0 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.inline-form select, .inline-form input { width: auto; flex: 1 1 120px; min-width: 100px; }
.chk { display: flex; align-items: center; gap: 8px; }
.chk input { width: auto; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 10px 0 0; }
.photos figure { margin: 0; display: grid; gap: 6px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #eef1f0; }
.stack label.chk { flex-direction: row; align-items: center; justify-content: flex-start; text-align: left; }

/* 휴대폰 (앱처럼) : 아래쪽 탭 메뉴, 표는 카드로, 손가락 크기 버튼 (인쇄에는 안 씀) */
@media screen and (max-width: 640px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  header nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0; gap: 0; background: var(--t9);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0, 0, 0, .18); }
  header nav a { flex: 1 0 auto; min-width: 62px; text-align: center; padding: 12px 8px; border-bottom: 0; border-top: 3px solid transparent; font-size: 14px; }
  header nav a.on { border-top-color: var(--t2); border-bottom: 0; }
  .tbl-wrap table:not(.form) { min-width: 0 !important; }
  .tbl-wrap table:not(.form) colgroup, .tbl-wrap table:not(.form) thead { display: none; }
  .tbl-wrap table:not(.form), .tbl-wrap table:not(.form) tbody, .tbl-wrap table:not(.form) tr, .tbl-wrap table:not(.form) td { display: block; width: 100%; }
  .tbl-wrap table:not(.form) tr { border-bottom: 10px solid var(--bg); padding: 6px 0; }
  /* 칸 이름은 내용 위 한 줄 (내용이 여러 조각이어도 흩어지지 않게) */
  .tbl-wrap table:not(.form) td { text-align: left; padding: 5px 12px; border: 0; }
  .tbl-wrap table:not(.form) td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
  .tbl-wrap table:not(.form) td[data-label=""]::before, .tbl-wrap table:not(.form) td:not([data-label])::before { display: none; }
  .tbl-wrap table:not(.form) td.num { text-align: left; }
  .dev { grid-template-columns: 1fr; gap: 4px; }
  .dev .waste { text-align: left; }
  .cal { padding: 10px 6px; }
  .cal-grid td a { height: 44px; }
  .vcards { grid-template-columns: 1fr; }
  button { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
}
@media print { header nav { display: none; } }
.cal-grid { min-width: 0; }
.cal-grid th, .cal-grid td { padding: 2px; border-bottom: 0; }
.cal-grid tbody tr:hover td { background: transparent; }
.stack label.chk { display: flex; }
.stack label.chk input { flex: 0 0 auto; width: auto; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { min-width: 36px; padding: 4px 10px; }
.stepper b { min-width: 28px; text-align: center; }
.spares { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; align-items: end; }
.spares label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.spares input { width: 100%; }
.equip { font-weight: 600; margin: 0 0 4px; }
a.button { display: inline-block; padding: 10px 16px; border-radius: 10px; background: var(--t6); color: #fff; text-decoration: none; font-weight: 600; }
a.button:hover { background: var(--t8); }

/* 관리자 2단계 인증 : 글자 열쇠 · 비상 코드 */
.key code { font-size: 20px; letter-spacing: 1px; word-break: break-all; }
.codes { columns: 2; font-size: 17px; padding-left: 20px; }
.codes code { letter-spacing: 1px; }

/* 업체 상태 안내 띠 (체험 끝 · 연체 · 보기만) · 빨간 꼬리표 */
.banner { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 12px; font-weight: 600; }
.tag.bad { background: #fde8e6; color: var(--bad); }
