:root {
  --bg: #F0F7FF;
  --card: #FFFFFF;
  --ink: #1F2A37;
  --muted: #6B7A8C;
  --primary: #4A90D9;
  --primary-dark: #2F6FB5;
  --sun: #FFB830;
  --ok: #2EBD7B;
  --bad: #E85D5D;
  --radius: 18px;
  --shadow: 0 4px 14px rgba(31, 42, 55, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  overscroll-behavior-y: none;
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

button { font: inherit; border: none; cursor: pointer; background: none; color: inherit; }
input, textarea, select { font: inherit; }
img { max-width: 100%; }
.hidden { display: none !important; }

/* ---------- wspólne ---------- */
.screen { flex: 1; display: flex; flex-direction: column; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }

.btn {
  display: block; width: 100%; padding: 15px; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-weight: 700; font-size: 17px;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn.secondary { background: #E4EDF7; color: var(--primary-dark); }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.small { width: auto; padding: 10px 16px; font-size: 15px; border-radius: 12px; display: inline-block; }
.btn:disabled { opacity: .5; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"], .field input[type="password"], .field input[type="number"],
.field textarea, .field select {
  width: 100%; padding: 13px 14px; border: 2px solid #DCE6F2; border-radius: 14px;
  background: #fff; font-size: 16px; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }

h1 { font-size: 26px; margin-bottom: 4px; }
h2 { font-size: 20px; margin-bottom: 10px; }
.sub { color: var(--muted); font-size: 15px; margin-bottom: 20px; }

.toast {
  position: fixed; bottom: calc(28px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 15px; font-weight: 600; z-index: 200; max-width: 90vw; text-align: center;
  animation: pop .2s ease;
}
.toast.error { background: var(--bad); }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* ---------- ekran wyboru profilu ---------- */
.login-hero { text-align: center; padding: 36px 0 24px; }
.login-hero .emoji { font-size: 64px; display: block; margin-bottom: 10px; }
.profiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.profile-tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 10px; text-align: center; transition: transform .08s ease;
}
.profile-tile:active { transform: scale(.95); }
.profile-tile .avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center; font-size: 40px;
}
.profile-tile .name { font-weight: 700; font-size: 17px; }
.profile-tile .role { font-size: 13px; color: var(--muted); }

/* ---------- PIN pad ---------- */
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 22px 0 30px; }
.pin-dot { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--primary); }
.pin-dot.filled { background: var(--primary); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 0 auto; width: 100%; }
.pinpad button {
  aspect-ratio: 1; border-radius: 50%; background: var(--card); box-shadow: var(--shadow);
  font-size: 28px; font-weight: 700; transition: transform .08s ease;
}
.pinpad button:active { transform: scale(.92); background: #E4EDF7; }
.pinpad button.ghost { background: none; box-shadow: none; font-size: 22px; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; padding: 8px 0; font-size: 15px; }

/* ---------- nagłówek dziecka ---------- */
.child-header {
  display: flex; align-items: center; gap: 12px; padding: 6px 2px 16px;
}
.child-header .avatar {
  width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 30px; flex-shrink: 0;
}
.child-header .hello { flex: 1; }
.child-header .hello .hi { font-size: 14px; color: var(--muted); }
.child-header .hello .name { font-size: 20px; font-weight: 800; }
.points-badge {
  background: linear-gradient(135deg, var(--sun), #FF9F1C); color: #fff;
  border-radius: 16px; padding: 8px 14px; font-weight: 800; font-size: 17px;
  box-shadow: var(--shadow); white-space: nowrap;
}

.progress-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 18px; }
.progress-card .label { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.progress-bar { height: 14px; background: #E4EDF7; border-radius: 7px; overflow: hidden; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--ok), #6FDCA8); border-radius: 7px; transition: width .4s ease; }

.section-title { font-size: 15px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }

/* ---------- karta wyzwania (dziecko) ---------- */
.challenge-item {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px;
  transition: transform .08s ease;
}
.challenge-item:active { transform: scale(.98); }
.challenge-item .status-icon {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.challenge-item.todo .status-icon { background: #E4EDF7; }
.challenge-item.pending .status-icon { background: #FFF1D6; }
.challenge-item.approved .status-icon { background: #DCF5E9; }
.challenge-item.rejected .status-icon { background: #FBDDDD; }
.challenge-item .info { flex: 1; min-width: 0; }
.challenge-item .title { font-weight: 700; font-size: 16px; }
.challenge-item.approved .title { text-decoration: line-through; color: var(--muted); }
.challenge-item .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.challenge-item .pts { font-weight: 800; color: var(--sun); white-space: nowrap; }

/* ---------- arkusz (modal dolny) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 45, .45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 24px 24px 0 0;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto; animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } }
.sheet .drag { width: 44px; height: 5px; background: #C9D6E4; border-radius: 3px; margin: 0 auto 16px; }
.sheet h2 { font-size: 22px; }
.sheet .desc { color: var(--muted); margin: 8px 0 14px; white-space: pre-wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; background: #E4EDF7; color: var(--primary-dark); font-size: 13px; font-weight: 700; border-radius: 10px; padding: 5px 10px; margin-right: 6px; }
.badge.warn { background: #FFF1D6; color: #B07508; }
.badge.okb { background: #DCF5E9; color: #17724A; }
.badge.badb { background: #FBDDDD; color: #A33030; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.photo-grid img, .photo-grid .ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }
.photo-grid .add-photo {
  aspect-ratio: 1; border: 2px dashed #B9C9DB; border-radius: 12px; display: flex;
  flex-direction: column; align-items: center; justify-content: center; color: var(--muted);
  font-size: 13px; font-weight: 600; gap: 4px;
}
.photo-grid .add-photo span { font-size: 26px; }
.photo-thumb { position: relative; }
.photo-thumb .rm {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--bad); color: #fff; font-size: 14px; font-weight: 800; line-height: 24px; text-align: center;
}

.reject-note { background: #FBDDDD; color: #A33030; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }

/* ---------- rodzic ---------- */
.parent-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 14px; }
.parent-header h1 { font-size: 22px; }
.icon-btn { font-size: 22px; padding: 8px; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
  border-top: 1px solid #E2EAF3; display: flex; z-index: 50;
  padding-bottom: env(safe-area-inset-bottom); max-width: 100%;
}
.tabbar button {
  flex: 1; padding: 10px 4px 8px; text-align: center; font-size: 12px; font-weight: 700;
  color: var(--muted); display: flex; flex-direction: column; gap: 2px; align-items: center; position: relative;
}
.tabbar button .ico { font-size: 22px; }
.tabbar button.active { color: var(--primary); }
.tabbar .count {
  position: absolute; top: 4px; right: calc(50% - 26px); background: var(--bad); color: #fff;
  font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; line-height: 18px; padding: 0 4px;
}
.with-tabbar { padding-bottom: 90px !important; }

.fab {
  position: fixed; right: 18px; bottom: calc(78px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 30px; box-shadow: 0 6px 18px rgba(74, 144, 217, .45); z-index: 60;
}

.chal-admin { display: flex; align-items: center; gap: 10px; }
.chal-admin .info { flex: 1; min-width: 0; }
.chal-admin .title { font-weight: 700; }
.chal-admin .meta { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; }

.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); }
.check-row .avatar-sm { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 19px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { padding: 10px 4px; border-radius: 12px; background: #E4EDF7; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--primary); color: #fff; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; z-index: 2; }
.switch .track { position: absolute; inset: 0; background: #CBD8E6; border-radius: 15px; transition: .2s; }
.switch input:checked + .track { background: var(--ok); }
.switch .track::after {
  content: ''; position: absolute; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.switch input:checked + .track::after { left: 25px; }

.review-card .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.review-card .head .avatar-sm { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.review-card .head .who { flex: 1; }
.review-card .head .who .cname { font-weight: 700; }
.review-card .head .who .when { font-size: 13px; color: var(--muted); }
.review-actions { display: flex; gap: 10px; margin-top: 12px; }
.review-actions .btn { flex: 1; padding: 12px; }

.kid-stats { display: flex; gap: 10px; margin: 10px 0; }
.stat { flex: 1; background: #F2F7FD; border-radius: 14px; padding: 10px; text-align: center; }
.stat .num { font-size: 22px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }

.history-item { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid #EEF3F9; font-size: 14px; gap: 8px; }
.history-item:last-child { border-bottom: none; }
.history-item .t { flex: 1; }
.history-item .d { color: var(--muted); font-size: 12px; }

/* ---------- podgląd zdjęcia ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(10, 15, 22, .92); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 92dvh; border-radius: 12px; }

/* ---------- konfetti / celebracja ---------- */
.celebrate { text-align: center; padding: 30px 0; }
.celebrate .big { font-size: 70px; animation: bounce .6s ease; }
@keyframes bounce { 0% { transform: scale(.3); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ---------- setup ---------- */
.avatar-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-pick button { font-size: 26px; width: 48px; height: 48px; border-radius: 12px; background: #E4EDF7; }
.avatar-pick button.active { background: var(--primary); }
.setup-child { border: 2px solid #DCE6F2; border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fff; }
.setup-child .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; }
.setup-child .head button { color: var(--bad); font-weight: 700; font-size: 14px; }
