/* Злата CRM — темна тема Telegram (батько/адмін) і темно-синя (дитина) */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #1f2c3a);
  --card: var(--tg-theme-section-bg-color, #1f2c3a);
  --text: var(--tg-theme-text-color, #e1e1e1);
  --hint: var(--tg-theme-hint-color, #7a8e9b);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(255, 255, 255, 0.08);
  --ok: #4fc3a1;
  --bad: #ef6f6f;
  --warn: #ffb74d;
  --gold: #ffc94d;
  --radius: 14px;
}
body.child {
  --bg: #0a1226;
  --bg2: #0f1b36;
  --card: #13224a;
  --text: #e8eeff;
  --hint: #8597c4;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --line: rgba(130, 160, 255, 0.12);
  background: radial-gradient(120% 60% at 50% -10%, #1b3474 0%, #0a1226 60%) fixed, #0a1226;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.app { padding: 14px 14px 90px; max-width: 720px; margin: 0 auto; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; }

.loading { display: flex; justify-content: center; padding-top: 30vh; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* шапка */
.hdr { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.hdr h1 { font-size: 22px; font-weight: 700; }
.hdr .sub { font-size: 12px; color: var(--hint); }
.child-select, select.inp, input.inp, textarea.inp {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font-size: 14px; outline: none; width: 100%;
}
.child-select { width: auto; max-width: 50%; }
textarea.inp { min-height: 64px; resize: vertical; }
.inp:focus { border-color: var(--accent); }

/* вкладки (нижня панель) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; gap: 2px;
  background: var(--bg2);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab { flex: 1; background: none; border: none; border-radius: 10px; padding: 6px 2px; font-size: 11px; color: var(--hint); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab .ic { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* картки */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 560px) { .cards.c4 { grid-template-columns: repeat(4, 1fr); } }
.card { background: var(--card); border-radius: var(--radius); padding: 12px; border: 1px solid var(--line); }
.card .lbl { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.3px; }
.card .val { font-size: 22px; font-weight: 700; color: var(--accent); line-height: 1.2; margin-top: 2px; }
.card .val.gold { color: var(--gold); }
.card .val.ok { color: var(--ok); }
.card .val.bad { color: var(--bad); }
.card .sub { font-size: 11px; color: var(--hint); margin-top: 2px; }

.block { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; border: 1px solid var(--line); }
.block h2 { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.block h2 .act { font-size: 13px; font-weight: 500; color: var(--accent); background: none; border: none; cursor: pointer; }
.hint { color: var(--hint); font-size: 12px; }
.empty { color: var(--hint); text-align: center; padding: 16px 8px; font-size: 13px; }
.sec-title { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.4px; margin: 16px 4px 8px; }

/* рядки списків */
.row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: none; }
.row .em { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row .m { font-size: 12px; color: var(--hint); margin-top: 1px; }
.row .r { text-align: right; flex-shrink: 0; font-size: 13px; }
.row.off { opacity: 0.45; }
.pts { color: var(--gold); font-weight: 600; }
.pen { color: var(--bad); font-size: 11px; }

.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--bg2); color: var(--hint); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: rgba(79,195,161,0.15); color: var(--ok); border-color: transparent; }
.chip.bad { background: rgba(239,111,111,0.15); color: var(--bad); border-color: transparent; }
.chip.warn { background: rgba(255,183,77,0.15); color: var(--warn); border-color: transparent; }
.chip.acc { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); border-color: transparent; }

/* чек-лист дитини */
.check { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 12px; margin-bottom: 8px; cursor: pointer; transition: transform 0.12s, background 0.2s; }
.check:active { transform: scale(0.98); }
.check .box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--hint); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; transition: all 0.2s; }
.check.done .box { background: var(--ok); border-color: var(--ok); }
.check.done .t { text-decoration: line-through; opacity: 0.6; }
.check.missed .box { background: var(--bad); border-color: var(--bad); }
.check.excused .box { border-style: dashed; }
.check .main { flex: 1; min-width: 0; }
.check .t { font-weight: 500; font-size: 15px; }
.check .m { font-size: 12px; color: var(--hint); }

.hero { background: linear-gradient(135deg, #2a4fae 0%, #1a2f6b 55%, #14224d 100%); border-radius: 20px; padding: 18px; margin-bottom: 14px; display: flex; align-items: center; gap: 16px; border: 1px solid rgba(130,160,255,0.2); box-shadow: 0 10px 30px rgba(10,20,60,0.5); }
.hero .hi { font-size: 20px; font-weight: 700; }
.hero .hs { font-size: 13px; color: #b8c8f2; margin-top: 2px; }
.hero .bal { margin-top: 10px; display: inline-flex; align-items: baseline; gap: 6px; background: rgba(255,255,255,0.08); padding: 6px 12px; border-radius: 20px; }
.hero .bal b { color: var(--gold); font-size: 18px; }
.ring { width: 84px; height: 84px; flex-shrink: 0; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .rt { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.ring .rt small { font-size: 10px; font-weight: 400; color: #b8c8f2; }

/* смуги прогресу і графіки */
.bar { height: 8px; background: var(--bg2); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.4s; }
.bar.gold > i { background: linear-gradient(90deg, #ffb74d, #ffd86b); }
.bar.ok > i { background: var(--ok); }
.bar.bad > i { background: var(--bad); }
.catrow { margin-bottom: 10px; }
.catrow .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.daychart { display: flex; align-items: flex-end; gap: 2px; height: 90px; padding-top: 6px; }
.daychart .d { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.daychart .d i { display: block; background: var(--line); border-radius: 3px 3px 0 0; min-height: 2px; }
.daychart .d i.f { background: var(--accent); }
.daychart .d.today i { outline: 1px solid var(--gold); }
.daylbl { display: flex; justify-content: space-between; font-size: 10px; color: var(--hint); margin-top: 4px; }

/* кнопки */
.btn { background: var(--accent); color: var(--accent-text); border: none; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 500; cursor: pointer; }
.btn.sec { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: rgba(239,111,111,0.15); color: var(--bad); }
.btn.ok { background: rgba(79,195,161,0.18); color: var(--ok); }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.fab { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 15; width: 54px; height: 54px; border-radius: 50%; font-size: 28px; line-height: 1; padding: 0; box-shadow: 0 6px 18px rgba(0,0,0,0.4); }

/* сегменти / фільтри */
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; overflow-x: auto; }
.seg button { flex: 1; background: none; border: none; border-radius: 8px; padding: 7px 8px; font-size: 13px; color: var(--hint); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.days { display: flex; gap: 5px; }
.days button { flex: 1; padding: 8px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--hint); cursor: pointer; font-size: 12px; }
.days button.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthnav b { font-size: 16px; text-transform: capitalize; }
.monthnav button { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 34px; cursor: pointer; font-size: 16px; }

/* форми в нижньому листі */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.sheet-bg.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 90vh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform 0.25s ease; max-width: 720px; margin: 0 auto; border-top: 1px solid var(--line); }
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 18px; margin-bottom: 12px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 5px; }
.field2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.switch input { width: 44px; height: 26px; appearance: none; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--hint); transition: all 0.2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 20px; background: #fff; }

.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -300%); visibility: hidden; background: #26344a; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; transition: transform 0.25s; font-size: 14px; max-width: 90%; box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.err { background: #5a2430; }

.reward { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.reward .em { font-size: 30px; }
.reward .main { flex: 1; min-width: 0; }
.reward .t { font-weight: 600; }
.reward .bar { margin-top: 6px; height: 6px; }
.gate { text-align: center; padding: 60px 20px; }
.gate .big { font-size: 56px; margin-bottom: 12px; }
.gate h2 { font-size: 20px; margin-bottom: 8px; }
.gate p { color: var(--hint); }
.warnbox { background: rgba(255,183,77,0.12); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.okbox { background: rgba(79,195,161,0.12); color: var(--ok); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
