:root {
  --bg: #f4f5f7; --card: #fff; --line: #dfe2e7; --text: #1d232c; --sub: #667085;
  --primary: #1f4fd8; --hpt: #0a7d55; --pt: #7a3fc4; --warn: #b45309; --warn-bg: #fff4dc;
  --danger: #c0271d; --danger-bg: #fde8e6; --ok: #0a7d55; --ok-bg: #e3f5ec;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* 가로 스크롤 원천 차단: 페이지는 세로로만 움직인다. (hidden 은 clip 을 모르는 구형 브라우저용) */
html, body { max-width: 100%; overflow-x: hidden; overflow-x: clip; overscroll-behavior-x: none; }
body { touch-action: pan-y; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.sub { color: var(--sub); font-size: 13px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand span { color: var(--sub); font-size: 12px; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; color: var(--sub); }
.tab.on { background: #e8eefc; color: var(--primary); font-weight: 700; }
.tab .n { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; text-align: center; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.panel.alert { border-color: #f0b4ae; }
.panel.caution { border-color: #f1cf8a; }
.empty { color: var(--sub); font-size: 13px; padding: 4px 0; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f5f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1a43b8; }
.btn.danger { color: var(--danger); border-color: #f0b4ae; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #eceff4; color: #3b4658; white-space: nowrap; }
.badge.hpt { background: #dff3ea; color: var(--hpt); }
.badge.pt { background: #efe4fb; color: var(--pt); }
.badge.none { background: #fff4dc; color: var(--warn); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.repeat { background: var(--danger); color: #fff; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

/* 오늘 할 일 */
.todo-item { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.todo-item:first-of-type { border-top: 0; }
.todo-item .who { font-weight: 600; }

/* 파이프라인 */
.board { display: grid; grid-template-columns: repeat(6, minmax(190px, 1fr)); gap: 10px; overflow-x: auto; align-items: start; }
.col { background: #eaedf2; border-radius: 10px; padding: 8px; min-height: 120px; }
.col h3 { display: flex; justify-content: space-between; margin: 2px 4px 2px; }
.col .next { font-size: 12px; color: var(--sub); margin: 0 4px 8px; }
.mini { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; width: 100%; text-align: left; font: inherit; display: block; }
.mini:hover { border-color: var(--primary); }
.mini .name { font-weight: 700; }
.mini .meta { font-size: 13px; color: var(--sub); }
.mini .flags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* 표 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--sub); font-weight: 600; font-size: 13px; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f5f7fb; }
.scroll-x { overflow-x: auto; }

/* 대시보드 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; }
.stat { min-width: 0; }
/* 대시보드 표: 칸 너비를 고정 비율로 나눠 좁은 화면에서도 넘치지 않게 한다 */
table.fit { table-layout: fixed; }
table.fit th, table.fit td { white-space: normal; word-break: keep-all; overflow-wrap: anywhere; padding: 8px 4px; }
.stat .big { font-size: 34px; font-weight: 800; line-height: 1.2; }
.stat .big small { font-size: 14px; font-weight: 500; color: var(--sub); }

/* 폼 */
.dlg { border: 0; border-radius: 12px; padding: 0; width: calc(100vw - 16px); max-width: 560px; max-height: 92vh; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dlg.wide { max-width: 860px; }
.dlg::backdrop { background: rgba(20, 25, 35, .45); }
.dlg-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.dlg-body { padding: 14px 18px 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid2 .full { grid-column: 1 / -1; }
.grid2 > * { min-width: 0; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--sub); }
input[type=text], input[type=tel], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  font: inherit; color: var(--text); padding: 7px 9px; border: 1px solid #c9ced6; border-radius: 8px; background: #fff; width: 100%; min-width: 0; max-width: 100%;
}
input[type=password] { font: inherit; color: var(--text); padding: 9px 10px; border: 1px solid #c9ced6; border-radius: 8px; background: #fff; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
.ro { padding: 7px 9px; border: 1px dashed #c9ced6; border-radius: 8px; color: var(--text); background: #f8f9fb; }
.hint { font-size: 12px; color: var(--warn); min-height: 0; }
.sec { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.next-box { background: #eef3ff; border: 1px solid #c9d7fb; border-radius: 10px; padding: 12px 14px; }
.next-box.red { background: var(--danger-bg); border-color: #f0b4ae; }

.msg { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.msg-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; flex-wrap: wrap; }
.msg-head .t { font-weight: 600; }
.msg.na .t, .msg.na .sub { color: #9aa3b0; }
.msg-body { padding: 0 10px 10px; }
.msg-body textarea { min-height: 210px; font-size: 14px; }
.warnline { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 6px 9px; font-size: 13px; margin-bottom: 6px; }
.log { font-size: 13px; color: var(--sub); max-height: 160px; overflow: auto; margin: 0; padding-left: 18px; }

.toast { position: fixed; inset: auto auto 24px 50%; margin: 0; border: 0; transform: translateX(-50%); background: #1d232c; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 99; font-size: 14px; }

/* 저장 상태 */
.sync.saving { color: var(--warn); }
.sync.error { color: var(--danger); font-weight: 700; }
.linkbtn { border: 0; background: none; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }

/* 화면 하단: 개인정보처리방침 링크 */
a.btn { display: inline-block; text-decoration: none; }
.foot { display: flex; justify-content: center; padding: 4px 16px 28px; }
.url-line { font-size: 13px; color: var(--sub); overflow-wrap: anywhere; min-width: 0; }

/* PIN 화면 */
.gate { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px 20px; display: flex; flex-direction: column; gap: 12px; }
.gate-card h2 { margin: 0; }
.gate-card p { margin: 0; }
.gate-brand { display: flex; flex-direction: column; line-height: 1.3; }
.gate-brand span { color: var(--sub); font-size: 12px; }
.gate-msg { color: var(--danger); font-size: 13px; min-height: 18px; }
.gate-card .btn { padding: 10px 12px; }

@media (max-width: 760px) {
  .top { justify-content: space-between; gap: 8px; padding: 8px 10px; }
  .tabs { order: 3; flex: 0 0 100%; flex-wrap: wrap; gap: 2px; }
  .tab { white-space: nowrap; padding: 7px 8px; font-size: 14px; }
  /* 입력칸 글자가 16px보다 작으면 아이폰이 화면을 확대해 가로로 밀린다 */
  input[type=text], input[type=tel], input[type=number], input[type=datetime-local], input[type=search], input[type=password], select, textarea { font-size: 16px; }
  .btn { white-space: normal; }
  /* 파이프라인: 가로로 늘어놓지 않고 세로로 쌓는다 */
  .board { grid-template-columns: 1fr; overflow-x: visible; }
  .col { min-height: 0; }
  /* 고객 카드 목록: 표 대신 카드 모양으로 쌓는다 */
  .scroll-x { overflow-x: visible; }
  table.cust thead { display: none; }
  table.cust, table.cust tbody { display: block; }
  table.cust tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.cust td { display: block; border: 0; padding: 1px 0; white-space: normal; overflow-wrap: anywhere; min-width: 0; }
  table.cust td::before { content: attr(data-label) " "; color: var(--sub); font-size: 12px; }
  table.cust td[colspan] { grid-column: 1 / -1; }
  table.cust td[colspan]::before { content: none; }
  .todo-item { align-items: flex-start; }
  .todo-item > div { min-width: 0; overflow-wrap: anywhere; }
  .todo-item .btn { white-space: nowrap; flex: none; }
  .dlg-head { padding: 12px 12px; }
  .dlg-body { padding: 12px 12px 16px; }
  .dlg-head h2 { overflow-wrap: anywhere; }
  .toast { max-width: calc(100vw - 24px); width: max-content; }
}
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 10px; }
}
