/* DESIGN.md v1.2 5.3 팔레트(WCAG AA), 1.2.6 반응형(360 / 600 / 900), 5.4 터치 대상 44px */
:root {
  --text: #1f2937;
  --sub: #4b5563;
  --bg: #ffffff;
  --soft: #f3f4f6;
  --line: #6b7280;
  --primary: #1d4ed8;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  --ok: #166534;
  --ok-bg: #f0fdf4;
  --warn: #92400e;
  --warn-bg: #fffbeb;
  --info: #1e40af;
  --info-bg: #eff6ff;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  overflow-wrap: anywhere;
}
body.modal-open { overflow: hidden; }
h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
p { margin: 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 포커스 표시: 제거하지 않는다 (5.1) */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
h2[tabindex="-1"]:focus, div[tabindex="-1"]:focus { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 버튼 */
.btn {
  min-height: 44px; min-width: 44px; padding: 8px 14px;
  border: 2px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1e40af; border-color: #1e40af; }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.btn.block { width: 100%; min-height: 48px; }
.btn.icon { font-size: 22px; padding: 0; width: 44px; line-height: 1; }
.btn:disabled, .btn[aria-disabled="true"] { color: var(--sub); background: var(--soft); border-color: var(--line); cursor: not-allowed; }
.btn.primary:disabled { background: var(--sub); border-color: var(--sub); color: #fff; }

/* 폼 */
.field { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.field > label, legend { display: block; font-weight: 600; margin-bottom: 4px; padding: 0; }
input[type="text"], input[type="password"], input[type="date"], input[type="time"], textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 2px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--err); }
input[readonly] { background: var(--soft); }
.hint { color: var(--sub); font-size: 14px; margin-top: 4px; }
.field-error { color: var(--err); font-size: 14px; margin-top: 4px; font-weight: 600; }
.field-error::before { content: "⚠ "; }
.pin-row { display: flex; gap: 8px; }
.pin-row input { flex: 1; min-width: 0; }
.opt { display: flex; align-items: center; min-height: 44px; gap: 6px; flex-wrap: wrap; }
.opt input[type="radio"], .opt input[type="checkbox"] { width: 24px; height: 24px; margin: 0 4px 0 0; flex: none; accent-color: var(--primary); }
.opt label { font-weight: 400; margin: 0; flex: 1; min-height: 44px; display: flex; align-items: center; }
.block-opt { align-items: flex-start; }
.block-opt label { min-height: 32px; font-weight: 600; }
.block-opt .hint { flex-basis: 100%; margin: -6px 0 6px 34px; }
.days { display: flex; flex-wrap: wrap; gap: 8px; }
.days .opt { min-height: 44px; border: 2px solid var(--line); border-radius: 8px; padding: 0 10px 0 8px; flex: 0 0 auto; }
.days .opt label { flex: none; min-width: 20px; }

/* 안내 박스: 색 + 아이콘 + 접두 텍스트 (4.2) */
.box { border: 2px solid; border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; }
.box p + p, .box h2 + p { margin-top: 4px; }
.box-head { display: flex; gap: 6px; font-weight: 700; margin-bottom: 4px; }
.box h2 { font-size: 16px; margin-bottom: 4px; }
.box.error { border-color: var(--err); background: var(--err-bg); color: var(--err); }
.box.warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.box.success { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.box.info { border-color: var(--info); background: var(--info-bg); color: var(--info); }
.box .btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.box .btn-row .btn { flex: 1 1 140px; }
.box .retry { margin-top: 8px; }

/* 부팅 */
.boot { min-height: 60vh; display: grid; place-items: center; padding: 16px; text-align: center; }
.spinner {
  display: inline-block; width: 28px; height: 28px; border: 4px solid var(--soft); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* S-1 */
.s1 { max-width: 440px; margin: 0 auto; padding: 24px 16px 32px; }
.s1 h1 { margin-bottom: 8px; }
.s1 .intro { color: var(--sub); margin-bottom: 14px; }
.s1 #s1-status:not(:empty) { margin-bottom: 14px; }
.s1 .notice { margin-top: 18px; }

/* S-2 레이아웃 */
.s2 { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 0; }
.top-user { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12em; font-weight: 600; }
.layout { display: block; }
.layout > section { margin-bottom: 20px; min-width: 0; }
#logout-error:not(:empty) { margin-bottom: 8px; }

/* A. 카운터 */
.a h2 { margin-bottom: 8px; }
.counters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.card { background: var(--soft); border-radius: 8px; padding: 8px 4px; text-align: center; display: flex; flex-direction: column; min-width: 0; }
.card .num { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.card .lbl { color: var(--sub); font-size: 14px; }
.done-line { margin-top: 8px; font-weight: 600; color: var(--ok); }
#c-error:not(:empty) { margin-top: 8px; }

/* B. 캘린더 */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.cal-nav h2 { flex: 1; text-align: center; }
.today-btn { margin: 4px 0 8px; }
.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid th { font-size: 14px; color: var(--sub); font-weight: 600; padding: 4px 0; text-align: center; }
.grid td { padding: 0; text-align: center; }
.day {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  width: 100%; height: 52px; padding: 2px 0 0; border: 2px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.day:hover { background: var(--soft); }
.day.other { color: var(--sub); }
.day .n { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; line-height: 1; }
.day.today .n { border-color: var(--text); font-weight: 800; }
.day .sub { display: flex; align-items: center; justify-content: center; gap: 2px; height: 16px; font-size: 12px; line-height: 16px; }
.day .dot { color: var(--primary); font-size: 10px; }
.day .tl { display: none; }
.day.sel { background: var(--primary); color: #fff; }
.day.sel .n { border-color: transparent; }
.day.sel.today .n { border-color: #fff; }
.day.sel .dot { color: #fff; }
.day.sel:hover { background: #1e40af; }
#cal-error:not(:empty) { margin-top: 8px; }

/* C. 목록 */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.list-head h2 { flex: 1 1 12em; min-width: 0; }
.add-btn {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  min-height: 48px; z-index: 20; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.rows { list-style: none; margin: 0; padding: 0; }
.grp-title { font-size: 14px; color: var(--sub); font-weight: 700; margin: 12px 0 4px; }
.grp-title:first-child { margin-top: 0; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.chk { position: relative; width: 44px; height: 44px; }
.chk input { position: absolute; inset: 0; width: 44px; height: 44px; margin: 0; opacity: 0; cursor: pointer; }
.chk .box-ic2 {
  position: absolute; left: 10px; top: 10px; width: 24px; height: 24px; border: 2px solid var(--line); border-radius: 6px;
  background: var(--bg); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; line-height: 1;
  pointer-events: none;
}
.chk input:checked + .box-ic2 { background: var(--primary); border-color: var(--primary); }
.chk input:focus-visible + .box-ic2 { outline: 3px solid var(--primary); outline-offset: 3px; }
.row .main { min-width: 0; padding-top: 9px; }
.row label {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; font-weight: 600;
}
.row .time { font-variant-numeric: tabular-nums; margin-right: 6px; }
.row.done label .title { text-decoration: line-through; }
.row.done label { color: var(--sub); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; min-width: 0; }
.badge { font-size: 14px; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; color: var(--sub); font-weight: 600; white-space: nowrap; }
.badge.done-b { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
.memo { font-size: 14px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 8em; }
.row-actions { grid-column: 2; display: flex; justify-content: flex-end; gap: 12px; margin-top: 4px; }
.row-actions .btn { min-height: 44px; }
.row-error { grid-column: 1 / -1; margin-top: 4px; }
.empty { padding: 16px 0; color: var(--text); }
.skel { height: 52px; background: var(--soft); border-radius: 8px; margin: 8px 0; }
.slow { color: var(--sub); font-size: 14px; margin-top: 4px; }

.foot { color: var(--sub); font-size: 14px; padding: 12px 0 8px; border-top: 1px solid var(--line); }

/* 토스트 / 오프라인 배너 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom));
  max-width: min(92vw, 520px); background: var(--ok-bg); color: var(--ok); border: 2px solid var(--ok);
  border-radius: 8px; padding: 10px 14px; z-index: 40; font-weight: 600;
}
.toast::before { content: "완료 · "; }
.offline { background: var(--warn-bg); color: var(--warn); border-bottom: 2px solid var(--warn); padding: 8px 16px; text-align: center; font-weight: 600; }
.offline::before { content: "알림 · "; }

/* 대화상자 */
dialog.dlg {
  border: 0; padding: 0; border-radius: 12px; color: var(--text); background: var(--bg);
  width: min(92vw, 480px); max-height: 90dvh; overflow: auto;
}
dialog.dlg::backdrop { background: rgba(17, 24, 39, 0.55); }
dialog.dlg:not(.sheet) { padding: 16px; }
dialog.dlg > h2 { margin-bottom: 8px; }
dialog.dlg p + p { margin-top: 6px; }
.strong-title { font-weight: 700; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.dlg-actions .btn { flex: 1 1 0; }
.dlg-actions.stack { flex-direction: column; align-items: stretch; }
.dlg-actions.inline .btn { flex: 1 1 0; }
.sheet form { display: flex; flex-direction: column; max-height: 90dvh; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dlg-body { padding: 14px 16px 4px; overflow: auto; flex: 1 1 auto; }
.sheet .dlg-actions { margin: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
#del-error:not(:empty), #delrep-error:not(:empty), #d5-alert:not(:empty) { margin-top: 10px; }

/* 360px ~ 599px: 시트는 전체 화면 */
@media (max-width: 599px) {
  dialog.sheet { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .sheet form { height: 100dvh; max-height: 100dvh; }
  .day .tl { display: none !important; }
}
@media (min-width: 420px) and (max-width: 599px) {
  .day .tl { display: inline !important; }
}
@media (min-width: 600px) {
  .day .tl { display: inline; }
  .add-btn { position: static; min-height: 44px; box-shadow: none; left: auto; right: auto; }
  .list-head h2 { flex-basis: auto; }
  .s2 { padding-bottom: 32px; }
  .toast { bottom: 24px; }
}
@media (min-width: 900px) {
  .s2 { max-width: 1100px; }
  .layout { display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); column-gap: 32px; align-items: start; }
  .layout > .a { grid-column: 1 / -1; }
  .layout > .b { grid-column: 1; }
  .layout > .c { grid-column: 2; grid-row: 2; }
}
