/* 온필드 디자인 시스템 — 자체 포함(외부 폰트/CDN 미사용, 오프라인 동작) */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e5e9f2;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --success: #16a34a;
  --success-d: #15803d;
  --danger: #dc2626;
  --danger-d: #b91c1c;
  --warn: #d97706;
  --info: #0891b2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "맑은 고딕", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 76px; /* 하단 탭바 여백 */
}
a { color: inherit; text-decoration: none; }
h1,h2,h3 { margin: 0 0 .4em; font-weight: 700; }

/* ===== 상단 앱바 ===== */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}
.appbar .brand { font-weight: 800; font-size: 18px; letter-spacing: -.5px; }
.appbar .brand span { color: var(--primary); }
.appbar .spacer { flex: 1; }
.appbar .who { font-size: 13px; color: var(--muted); text-align: right; }
.appbar .who b { color: var(--text); }
.appbar .bell { position: relative; font-size: 20px; margin-right: 6px; text-decoration: none; }
.appbar .bell .dot {
  position: absolute; top: -6px; right: -8px; min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 800;
  line-height: 16px; text-align: center;
}

/* ===== 레이아웃 ===== */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 640px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 카드 ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h2 { font-size: 16px; }
.card .sub { color: var(--muted); font-size: 13px; }

/* ===== 통계 타일 ===== */
.stat { text-align: left; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .num { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-top: 2px; }
.stat.accent .num { color: var(--primary); }
.stat.green .num { color: var(--success); }
.stat.red .num { color: var(--danger); }
.stat.warn .num { color: var(--warn); }

/* ===== 버튼 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: .15s; font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; font-size: 13px; }

/* 출근/퇴근 대형 버튼 */
.punch { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.punch button {
  border: none; border-radius: 18px; color: #fff; font-size: 20px; font-weight: 800;
  padding: 30px 0; cursor: pointer; transition: .15s; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.punch .in  { background: linear-gradient(135deg, #16a34a, #15803d); }
.punch .out { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.punch button:disabled { filter: grayscale(.6); opacity: .55; cursor: not-allowed; }
.punch .ico { font-size: 30px; }

/* ===== 배지 ===== */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.gray   { background: #eef1f6; color: #4b5563; }
.badge.green  { background: #dcfce7; color: #15803d; }
.badge.blue   { background: #dbeafe; color: #1d4ed8; }
.badge.red    { background: #fee2e2; color: #b91c1c; }
.badge.warn   { background: #fef3c7; color: #b45309; }

/* ===== 표 ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; white-space: nowrap; }
table.data thead th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); font-size: 13px; }
table.data tbody tr { border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child { border-bottom: none; }

/* ===== 폼 ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row .field { flex: 1; margin-bottom: 0; min-width: 130px; }

/* ===== 하단 탭바 ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar a .ico { font-size: 20px; }
.tabbar a.active { color: var(--primary); }

/* ===== 유틸 ===== */
.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 14px; } .mt2 { margin-top: 22px; }
.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 14px; z-index: 50; box-shadow: var(--shadow); max-width: 90%;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger-d); }
#map { height: 340px; border-radius: 12px; overflow: hidden; }
.gps-line { font-size: 13px; color: var(--muted); }

/* ===== 캘린더 ===== */
.cal-head { display:flex; align-items:center; justify-content:center; gap:16px; margin-bottom:12px; }
.cal-head .title { font-size:18px; font-weight:800; min-width:130px; text-align:center; }
.cal { display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.cal .dow { text-align:center; font-size:12px; color:var(--muted); font-weight:700; padding:4px 0; }
.cal .dow.sun { color:var(--danger); } .cal .dow.sat { color:var(--primary); }
.cal .cell { min-height:82px; border:1px solid var(--line); border-radius:8px; padding:6px; background:var(--surface-2); font-size:12px; overflow:hidden; }
.cal .cell.other { opacity:.35; }
.cal .cell.today { outline:2px solid var(--primary); }
.cal .cell.clickable { cursor:pointer; }
.cal .cell.clickable:hover { background:#eef2ff; }
.cal .cell .d { font-weight:700; font-size:12px; margin-bottom:4px; }
.cal .cell .d.sun { color:var(--danger); } .cal .cell .d.sat { color:var(--primary); }
.cal .cell .ev { background:#dbeafe; color:#1d4ed8; border-radius:5px; padding:1px 5px; margin-bottom:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cal .cell .ev.leave { background:#fef3c7; color:#b45309; }
@media (max-width:640px){ .cal .cell{ min-height:64px; font-size:11px; padding:4px; } }

/* ===== 터치 타깃 보강(모바일 오탭 방지) ===== */
.btn { min-height: 44px; }
.btn.sm { min-height: 34px; }
.tabbar a { min-height: 52px; justify-content: center; }
.field input, .field select, .field textarea { min-height: 44px; }

/* ===== 다크 모드 (OS 설정 자동 적용) ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #172033;
    --line: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-d: #2563eb;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.45);
  }
  .badge.gray  { background:#334155; color:#cbd5e1; }
  .badge.green { background:#14532d; color:#86efac; }
  .badge.blue  { background:#1e3a8a; color:#93c5fd; }
  .badge.red   { background:#7f1d1d; color:#fca5a5; }
  .badge.warn  { background:#78350f; color:#fcd34d; }
  .cal .cell.clickable:hover { background:#243049; }
  .cal .cell .ev { background:#1e3a8a; color:#bfdbfe; }
  .cal .cell .ev.leave { background:#78350f; color:#fcd34d; }
  #map, #attMap { background:#172033; }
}
