/* 약달력 웹 MVP — 시니어 친화 고대비 (Accessible & Ethical) */
:root {
  --primary: #0F172A;
  --secondary: #334155;
  --accent: #0369A1;
  --accent-dark: #075985;
  --bg: #F8FAFC;
  --fg: #020617;
  --muted: #E8ECF1;
  --border: #E2E8F0;
  --danger: #DC2626;
  --success: #15803D;
  --warn: #B45309;
  --radius: 14px;
  --font: 'Noto Sans KR', -apple-system, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 17px; }
html.font-small { font-size: 15px; }
html.font-large { font-size: 20px; }
html.font-xlarge { font-size: 23px; }

/* 고대비 모드 (접근성): 텍스트·테두리·포커스 강도 상향 */
html.hc {
  --fg: #000000;
  --primary: #000000;
  --secondary: #1E293B;
  --accent: #1D4ED8;
  --accent-dark: #1E3A8A;
  --bg: #FFFFFF;
  --muted: #E2E8F0;
  --border: #475569;
  --danger: #B91C1C;
  --success: #166534;
}
html.hc .card, html.hc .dose-item, html.hc .med-item, html.hc .chk-btn,
html.hc .seg button, html.hc .cond-btn, html.hc .field input,
html.hc .field select, html.hc .field textarea { border-width: 2px; }
html.hc :focus-visible { outline: 4px solid #1D4ED8 !important; outline-offset: 2px; }

/* 스킵 링크 (키보드·스크린리더) */
.skip-link {
  position: absolute; left: 0; top: -60px; z-index: 400;
  background: var(--primary); color: #fff; padding: 0.7rem 1.2rem;
  border-radius: 0 0 10px 0; font-weight: 700; text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); font-size: 1rem; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; position: relative; }
.view { padding: 1rem 1rem 5.5rem; }
.view.no-tab { padding-bottom: 2rem; }

/* ── 하단 탭 ── */
.tabbar[hidden] { display: none; } /* display:flex가 hidden 속성을 덮지 않도록 */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; background: #fff; border-top: 2px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; border: none; background: none;
  color: var(--secondary); font-size: 0.72rem; font-weight: 500;
  min-height: 56px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); font-weight: 700; }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 8px; }

/* ── 공통 컴포넌트 ── */
.page-title { font-size: 1.35rem; font-weight: 700; margin: 0.3rem 0 1rem; }
.card {
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 0.9rem;
}
.card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.6rem; color: var(--secondary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; font-weight: 700; font-size: 1.05rem;
  min-height: 52px; padding: 0 1.2rem; transition: background 0.15s;
  width: 100%;
}
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: #fff; color: var(--accent); border: 2px solid var(--accent); }
.btn-ghost { background: var(--muted); color: var(--secondary); }
.btn-danger-ghost { background: #fff; color: var(--danger); border: 2px solid #FECACA; }
.btn-sm { min-height: 42px; font-size: 0.92rem; width: auto; padding: 0 0.9rem; }
.btn:disabled { opacity: 0.45; cursor: default; }

.field { margin-bottom: 0.9rem; }
.field label { display: block; font-weight: 700; font-size: 0.92rem; margin-bottom: 0.35rem; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 50px; padding: 0.6rem 0.8rem;
  border: 2px solid var(--border); border-radius: 10px; background: #fff;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}
.field .hint { font-size: 0.82rem; color: var(--secondary); margin-top: 0.25rem; }
.field-error { color: var(--danger); font-size: 0.88rem; margin-top: 0.3rem; font-weight: 500; }

.row { display: flex; gap: 0.6rem; }
.row > * { flex: 1; }

/* 세그먼트 선택 (약 종류, 반복 등) */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-height: 48px; border: 2px solid var(--border); background: #fff;
  border-radius: 10px; font-size: 0.95rem; font-weight: 500; color: var(--secondary);
  white-space: nowrap; padding: 0 0.6rem;
}
.seg button.on { border-color: var(--accent); background: #E0F2FE; color: var(--accent-dark); font-weight: 700; }

/* ── 인증 화면 ── */
.auth-wrap { padding: 3rem 1.5rem 2rem; }
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo .mark { font-size: 3rem; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.auth-logo p { color: var(--secondary); font-size: 0.95rem; }
.auth-links { display: flex; justify-content: center; gap: 0.8rem; margin-top: 1.2rem; font-size: 0.92rem; }
.auth-links a { color: var(--secondary); text-decoration: none; font-weight: 500; }
.auth-links a:hover { color: var(--accent); }

/* ── 홈 ── */
.home-head { margin-bottom: 1rem; }
.home-head .date { font-size: 0.95rem; color: var(--secondary); font-weight: 500; }
.home-head h2 { font-size: 1.45rem; font-weight: 700; margin-bottom: 0.5rem; }
.day-nav { display: flex; align-items: center; gap: 0.5rem; }
.day-nav > button {
  width: 48px; height: 48px; flex-shrink: 0;
  border: 2px solid var(--border); border-radius: 10px; background: #fff;
  font-size: 1.3rem; color: var(--secondary);
}
.day-nav-label { flex: 1; text-align: center; }
.day-nav-label .date b { color: var(--accent-dark); }
.today-link {
  border: none; background: none; color: var(--accent); font-size: 0.85rem;
  font-weight: 700; text-decoration: underline; min-height: 32px; padding: 0 0.5rem;
}
.refill-banner {
  background: #FEF3C7; border: 1.5px solid #FCD34D; border-radius: var(--radius);
  padding: 0.8rem 1rem; margin-bottom: 0.9rem; font-size: 0.95rem; color: #78350F;
}
.dose-item {
  display: flex; align-items: center; gap: 0.8rem;
  background: #fff; border: 1.5px solid var(--border); border-left-width: 6px;
  border-radius: var(--radius); padding: 0.85rem 0.9rem; margin-bottom: 0.7rem;
}
.dose-item .icon { font-size: 1.7rem; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--muted); flex-shrink: 0; }
.dose-item .info { flex: 1; min-width: 0; }
.dose-item .time { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.dose-item .name { font-weight: 500; }
.dose-item .meta { font-size: 0.82rem; color: var(--secondary); }
/* 버튼 열 고정폭 — 상태가 바뀌어도 카드 레이아웃이 늘었다 줄었다 하지 않음 */
.dose-item .acts { display: flex; flex-direction: column; gap: 6px; flex: 0 0 118px; align-items: stretch; }
.chk-btn {
  width: 100%; min-height: 44px; padding: 0.35rem 0.5rem;
  border-radius: 10px; font-weight: 700; font-size: 0.95rem;
  border: 2px solid var(--border); background: #fff; color: var(--secondary);
  white-space: nowrap;
}
.chk-btn.taken { background: var(--success); border-color: var(--success); color: #fff; }
.chk-btn.skip { min-height: 36px; padding: 0.25rem 0.5rem; font-size: 0.82rem; font-weight: 500; border: none; background: none; text-decoration: underline; }
.chk-btn.skipped {
  background: var(--muted); border-color: var(--muted); color: var(--danger);
  font-weight: 700; text-decoration: none; padding: 0.35rem 0.5rem;
}
.dose-item .meta .reason { color: var(--danger); font-weight: 500; }
.status-badge { font-size: 0.8rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.status-missed { background: #FEE2E2; color: var(--danger); }

.cond-row { display: flex; gap: 0.6rem; }
.cond-btn {
  flex: 1; min-height: 72px; padding: 0.5rem 0.3rem;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.92rem; font-weight: 500; color: var(--secondary);
}
.cond-btn .emo { font-size: 1.8rem; }
.cond-btn.on { border-color: var(--accent); background: #E0F2FE; color: var(--accent-dark); font-weight: 700; }

/* ── 약등록 ── */
.med-cat { font-size: 0.9rem; font-weight: 700; color: var(--secondary); margin: 1rem 0 0.5rem; }
.med-item {
  display: flex; align-items: center; gap: 0.8rem;
  background: #fff; border: 1.5px solid var(--border); border-left-width: 6px;
  border-radius: var(--radius); padding: 0.85rem 0.9rem; margin-bottom: 0.7rem;
}
.med-item .icon { font-size: 1.7rem; }
.med-item .info { flex: 1; }
.med-item .name { font-weight: 700; font-size: 1.05rem; }
.med-item .meta { font-size: 0.84rem; color: var(--secondary); }
.med-item .qty-low { color: var(--warn); font-weight: 700; }
.fab {
  position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); right: max(16px, calc(50% - 224px));
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(3, 105, 161, 0.4); z-index: 90;
}
.time-chip { display: inline-flex; align-items: center; gap: 6px; background: #E0F2FE; color: var(--accent-dark); border-radius: 20px; padding: 6px 12px; font-weight: 700; margin: 0 6px 6px 0; font-variant-numeric: tabular-nums; }
.time-chip button { border: none; background: none; color: var(--accent-dark); font-size: 1.1rem; line-height: 1; padding: 2px; }
.icon-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-pick button { width: 48px; height: 48px; font-size: 1.4rem; border: 2px solid var(--border); border-radius: 10px; background: #fff; }
.icon-pick button.on { border-color: var(--accent); background: #E0F2FE; }
.color-pick { display: flex; gap: 8px; }
.color-pick button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; }
.color-pick button.on { border-color: var(--primary); }

/* ── 달력 ── */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; }
.cal-head h2 { font-size: 1.2rem; font-weight: 700; }
.cal-head button { width: 44px; height: 44px; border: 2px solid var(--border); border-radius: 10px; background: #fff; font-size: 1.1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid .dow { text-align: center; font-size: 0.78rem; font-weight: 700; color: var(--secondary); padding: 4px 0; }
.cal-grid .dow.sun { color: var(--danger); }
.cal-day {
  aspect-ratio: 1; border: 1.5px solid transparent; border-radius: 10px; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 0.95rem; font-variant-numeric: tabular-nums; color: var(--fg); position: relative;
}
.cal-day.other { color: #CBD5E1; }
.cal-day.today { border-color: var(--accent); font-weight: 700; }
.cal-day.sel { background: var(--accent); color: #fff; font-weight: 700; }
.cal-day .dots { display: flex; gap: 2px; height: 6px; }
.cal-day .dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.ok { background: var(--success); }
.dot.part { background: var(--warn); }
.dot.bad { background: var(--danger); }
.dot.sched { background: var(--accent); }
.cal-day.sel .dot { background: #fff; }
.sched-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.sched-item:last-child { border-bottom: none; }
.sched-item .t { font-weight: 700; }
.sched-item .del { margin-left: auto; border: none; background: none; color: var(--danger); font-size: 0.85rem; text-decoration: underline; min-height: 44px; padding: 0 0.5rem; }

/* ── 리포트 ── */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.7rem; margin-bottom: 0.9rem; }
.stat-tile { background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius); padding: 0.9rem; text-align: center; }
.stat-tile .num { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-tile .lbl { font-size: 0.85rem; color: var(--secondary); font-weight: 500; }
.stat-tile.hero { grid-column: 1 / -1; background: var(--primary); border-color: var(--primary); color: #fff; }
.stat-tile.hero .lbl { color: #CBD5E1; }
.stat-tile.hero .num { font-size: 2.6rem; }
.cond-trend { display: flex; gap: 4px; align-items: flex-end; }
.cond-trend .day { flex: 1; text-align: center; font-size: 0.72rem; color: var(--secondary); }
.cond-trend .emo { font-size: 1.3rem; display: block; }
.share-person { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.share-person:last-child { border-bottom: none; }
.share-person .nm { font-weight: 700; }
.share-person .sub { font-size: 0.82rem; color: var(--secondary); }
.share-person .right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
/* 시각 크기는 유지, 터치 영역만 44px 이상으로 확장 */
.switch input { opacity: 0; position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); z-index: 2; cursor: pointer; margin: 0; }
.switch .track { position: absolute; inset: 0; background: #CBD5E1; border-radius: 30px; transition: background 0.15s; }
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(22px); }
.invite-code-box { text-align: center; padding: 1rem; background: var(--muted); border-radius: var(--radius); margin: 0.8rem 0; }
.invite-code-box .code { font-size: 2.2rem; font-weight: 700; letter-spacing: 0.35em; font-variant-numeric: tabular-nums; color: var(--primary); }
.invite-code-box .exp { font-size: 0.85rem; color: var(--secondary); }

/* ── 설정 ── */
.set-row { display: flex; align-items: center; min-height: 56px; gap: 0.8rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row .lbl { flex: 1; font-weight: 500; }
.set-row select { min-height: 44px; border: 2px solid var(--border); border-radius: 10px; padding: 0 0.5rem; background: #fff; }

/* ── 모달 ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.55); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 480px; border-radius: 20px 20px 0 0;
  padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
}
.modal h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.9rem; }
.modal .modal-close { position: sticky; float: right; top: 0; border: none; background: var(--muted); width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem; }

/* ── PWA 설치 배너 ── */
.install-banner {
  position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 456px;
  display: flex; align-items: center; gap: 0.7rem;
  background: #fff; border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 0.7rem 0.8rem; z-index: 150;
  box-shadow: 0 4px 16px rgba(2, 6, 23, 0.18);
}
.install-banner .ib-icon { width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; }
.install-banner .ib-text { flex: 1; font-size: 0.88rem; line-height: 1.4; }
.install-banner .btn { flex: 0 0 auto; }
.install-banner .ib-close {
  border: none; background: none; color: var(--secondary); font-size: 1.3rem;
  min-width: 40px; min-height: 40px; flex-shrink: 0;
}

/* ── 토스트 ── */
.toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; padding: 0.75rem 1.3rem; border-radius: 12px;
  font-weight: 500; z-index: 300; max-width: 90%; text-align: center;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.empty { text-align: center; color: var(--secondary); padding: 2rem 1rem; }
.empty .big { font-size: 2.5rem; margin-bottom: 0.5rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
