:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --border: #dcdfd9;
  --text: #1a1c19;
  --muted: #5c6157;
  --primary: #2e6f4e;
  --on-primary: #ffffff;
  --error: #b3261e;
  --success: #2e7d32;
  --warn: #8a5a00;
  --chip: #eceee8;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --border: #333840;
    --text: #e6e6e3;
    --muted: #a3a9a0;
    --primary: #7ed6a3;
    --on-primary: #06301b;
    --error: #ffb4ab;
    --success: #8bd894;
    --warn: #e8bf72;
    --chip: #272b31;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Malgun Gothic", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.view { min-height: 100dvh; }

/* ── 로그인 ───────────────────────────────────────── */
#login-view { display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: -8px 0 6px; }

/* ── 폼 ──────────────────────────────────────────── */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, textarea {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
}
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
  font-weight: 600;
  padding: 12px 14px;
}
button.danger { color: var(--error); }
button.icon { border: none; background: none; font-size: 22px; padding: 4px 10px; line-height: 1; }

/* ── 레이아웃 ─────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top)) 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 19px; flex: 1; }

main {
  padding: 16px;
  padding-bottom: 150px;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress { height: 3px; background: var(--primary); animation: slide 1s linear infinite; }
@keyframes slide { from { opacity: .35 } 50% { opacity: 1 } to { opacity: .35 } }

nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  border: none; background: none; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted); padding: 9px 0;
}
nav button span { font-size: 19px; line-height: 1; }
nav button[aria-current="page"] { color: var(--primary); font-weight: 700; }
header .icon.on { color: var(--primary); }

.fab {
  position: fixed; right: 18px; z-index: 6;
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px;
  font-size: 28px; line-height: 1;
  background: var(--primary); color: var(--on-primary); border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
}

/* ── 카드 ─────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-head > div:first-child { flex: 1; min-width: 0; }
.title { font-size: 16px; font-weight: 600; }
.status { font-size: 13px; font-weight: 600; }
.status.pending { color: var(--primary); }
.status.success { color: var(--success); }
.status.failed, .status.missed { color: var(--error); }
.status.unknown { color: var(--warn); }

/* 빈자리 화면의 날짜 한 줄 */
.day { display: flex; flex-direction: column; gap: 4px; padding-top: 6px; border-top: 1px solid var(--border); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.hint { font-size: 13px; color: var(--muted); }

/* ── 칩 ──────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--chip);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
}
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; font-weight: 600; }
.chip:disabled { opacity: .35; }

/* ── 달력 ─────────────────────────────────────────── */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal-head { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal-head.sun { color: var(--error); }
.cal-head.sat { color: var(--primary); }
.cal-blank { aspect-ratio: 1; }
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 0;
}
/* 빈자리가 있는 날만 누를 수 있다 */
.cal-day.free { background: var(--chip); border-color: var(--border); color: var(--text); font-weight: 600; }
.cal-day.free .count { font-size: 11px; font-weight: 500; color: var(--primary); }
.cal-day.today { border-color: var(--primary); border-style: dashed; }
.cal-day[aria-pressed="true"] { background: var(--primary); border-color: transparent; color: var(--on-primary); }
.cal-day[aria-pressed="true"] .count { color: var(--on-primary); }
.cal-day:disabled { opacity: .45; }
.day-detail { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
/* 고른 날짜가 늘어도 다이얼로그가 세로로 흔들리지 않게 자리를 잡아 둔다 */
.picked-dates { min-height: 2.8em; margin-top: 6px; }
.siteplan { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 8px; }

/* ── 모달 ─────────────────────────────────────────── */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(460px, calc(100vw - 32px));
  max-height: min(86dvh, 720px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.modal-body h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* ── 오버레이·토스트 ──────────────────────────────── */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.45); }
.busy-box {
  background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 22px 26px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 300px; text-align: center; font-size: 14px;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(86px + env(safe-area-inset-bottom));
  background: #303030; color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

/* 로그인: 아이디 칩과 비밀번호를 한 줄에 둔다 (앱과 같은 구조) */
.login-row { display: flex; gap: 8px; align-items: center; }
.login-row .chips { flex: 0 0 auto; }
.login-row input { flex: 1 1 auto; min-width: 0; }
