/* CleanHome — стили (mobile-first, без внешних зависимостей) */
:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #71767f;
  --line: #e6e8ec;
  --accent: #10b981;
  --accent-dark: #059669;
  --green: #22c55e;
  --green-bg: #eafbf1;
  --yellow: #eab308;
  --yellow-bg: #fdf6d8;
  --red: #ef4444;
  --red-bg: #fdeaea;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(20, 24, 40, .07), 0 6px 18px rgba(20, 24, 40, .05);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
}
#app { max-width: 560px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; position: relative; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Общие ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.btn {
  display: inline-block; border-radius: 12px; padding: 12px 18px; font-weight: 600;
  transition: transform .06s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: #eef0f3; color: var(--text); }
.btn.danger { background: var(--red); color: #fff; }
.btn.wide { width: 100%; }
.hint { color: var(--muted); font-size: 13px; }
.form-error { color: var(--red); font-size: 14px; margin-top: 6px; }

#offline-banner {
  background: #fff7e0; color: #92600a; text-align: center; font-size: 13px; padding: 6px 10px;
}

/* ---------- Авторизация ---------- */
#view-auth { flex: 1; overflow-y: auto; }
.auth-wrap { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 28px 18px; gap: 18px; }
.auth-logo { text-align: center; }
.auth-logo img { width: 84px; height: 84px; border-radius: 22px; box-shadow: var(--shadow); }
.auth-logo h1 { margin-top: 12px; font-size: 26px; letter-spacing: .2px; }
.auth-logo p { color: var(--muted); margin-top: 4px; }
.auth-card { padding: 18px; }
.seg { display: flex; background: #eef0f3; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border-radius: 9px; padding: 9px; font-weight: 600; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fafbfc;
}
.auth-form input:focus { outline: none; border-color: var(--accent); background: #fff; }
.demo-row { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.demo-btns { display: flex; gap: 8px; margin-top: 8px; }
.demo-btns button {
  flex: 1; background: #f0fdf6; border: 1.5px solid #b9ecd3; border-radius: 12px; padding: 9px 6px; font-weight: 600;
}
.auth-note { text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Каркас приложения ---------- */
#view-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#topbar-title { font-weight: 700; font-size: 18px; }
#pages { flex: 1; overflow: hidden; display: flex; }
.page { flex: 1; overflow-y: auto; padding: 14px 14px 20px; display: none; -webkit-overflow-scrolling: touch; }
.page.active { display: block; }

#tabbar {
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 21px; padding: 4px; color: var(--muted); border-radius: 12px;
}
#tabbar button span { font-size: 11px; font-weight: 600; }
#tabbar button.active { color: var(--accent-dark); }

/* ---------- Главный экран (Дом) ---------- */
.hero-card { text-align: center; padding: 18px 16px; }
.hero-card .hero-pct { font-size: 40px; font-weight: 800; line-height: 1.1; }
.hero-card .hero-label { color: var(--muted); margin-top: 2px; }
.hero-bar { height: 8px; background: #edf0f3; border-radius: 4px; margin-top: 12px; overflow: hidden; }
.hero-bar i { display: block; height: 100%; border-radius: 4px; transition: width .5s ease; }
.hero-sub { display: flex; justify-content: center; gap: 14px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.hero-sub b { color: var(--text); }

.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .4px; }

.zone-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px; margin-bottom: 10px; transition: transform .06s ease;
}
.zone-card:active { transform: scale(.985); }
.zone-icon {
  width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0; background: #f0f2f5;
}
.zone-icon.green { background: var(--green-bg); }
.zone-icon.yellow { background: var(--yellow-bg); }
.zone-icon.red { background: var(--red-bg); }
.zone-mid { flex: 1; min-width: 0; }
.zone-name { font-weight: 700; font-size: 16px; }
.zone-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.zone-pct { text-align: right; flex-shrink: 0; }
.zone-pct b { font-size: 19px; font-weight: 800; }
.zone-pct .mini-bar { width: 58px; height: 5px; background: #edf0f3; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.zone-pct .mini-bar i { display: block; height: 100%; border-radius: 3px; }
.c-green { color: var(--green); } .bg-green { background: var(--green); }
.c-yellow { color: var(--yellow); } .bg-yellow { background: var(--yellow); }
.c-red { color: var(--red); } .bg-red { background: var(--red); }

/* ---------- Экран зоны ---------- */
#zone-screen {
  position: absolute; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column; animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
#zone-header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.icon-btn { font-size: 22px; padding: 4px 10px; border-radius: 10px; }
#zone-title { font-weight: 700; font-size: 18px; }
#zone-sub { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }
#zone-list { flex: 1; overflow-y: auto; padding: 14px 14px 24px; }

.task-row {
  position: relative; display: flex; align-items: stretch; gap: 10px; width: 100%; text-align: left;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 12px 18px; margin-bottom: 10px; overflow: hidden;
  transition: transform .06s ease;
}
.task-row:active { transform: scale(.985); }
.task-row::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
}
.task-row.green::before { background: var(--green); }
.task-row.yellow::before { background: var(--yellow); }
.task-row.red::before { background: var(--red); }
.task-row.done-today { border: 1.5px solid #a7e8c3; background: #f4fdf8; }
.task-mid { flex: 1; min-width: 0; }
.task-title { font-weight: 700; font-size: 16px; }
.task-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.task-sub .who { display: inline-flex; align-items: center; gap: 4px; }
.task-right { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 5px; flex-shrink: 0; }
.task-pct { font-weight: 800; font-size: 18px; }
.task-bar { width: 64px; height: 6px; background: #edf0f3; border-radius: 3px; overflow: hidden; }
.task-bar i { display: block; height: 100%; border-radius: 3px; }
.badge-today {
  display: inline-block; background: var(--green-bg); color: var(--accent-dark);
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 2px 8px; margin-left: 6px;
}
.pill {
  display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 700;
}
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.yellow { background: var(--yellow-bg); color: #a16207; }
.pill.green { background: var(--green-bg); color: var(--accent-dark); }
.empty-note { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Чат ---------- */
#page-chat { padding: 0; }
#page-chat.active { display: flex; flex-direction: column; }
.chat-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-input-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.chat-input-bar input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 16px;
  padding: 11px 14px; background: #fafbfc;
}
.chat-input-bar input:focus { outline: none; border-color: var(--accent); background: #fff; }
.chat-input-bar .btn { padding: 10px 16px; }
.chat-list { display: flex; flex-direction: column; padding: 12px 12px 16px; min-height: 100%; }
.chat-day { text-align: center; margin: 14px 0 8px; }
.chat-day span { background: #e8ebef; color: var(--muted); font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 3px 12px; }
.chat-msg { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-end; max-width: 92%; }
.chat-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-ava { width: 32px; height: 32px; border-radius: 50%; background: #eef0f3; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }
.chat-bubble { background: var(--card); border-radius: 16px 16px 16px 5px; box-shadow: var(--shadow); padding: 8px 12px 7px; }
.mine .chat-bubble { background: #d8f5e7; border-radius: 16px 16px 5px 16px; }
.chat-who { font-size: 12px; font-weight: 700; color: var(--accent-dark); margin-bottom: 2px; }
.chat-text { font-size: 15px; white-space: pre-wrap; word-wrap: break-word; }
.chat-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; }
.chat-system { align-self: center; text-align: center; max-width: 88%; margin: 8px 0; }
.chat-system span { display: inline-block; background: #e8ebef; color: #55606c; font-size: 13px; border-radius: 999px; padding: 6px 14px; }
.chat-system.summary span { background: #e0e7ff; color: #3730a3; }
.chat-loadmore { text-align: center; margin: 4px 0 10px; }
.chat-loadmore button { color: var(--accent-dark); font-weight: 700; padding: 8px 14px; }

/* ---------- История (лог, оверлей из «Ещё») ---------- */
#hist-screen {
  position: absolute; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column; animation: slidein .18s ease;
}
#hist-header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
#hist-title { font-weight: 700; font-size: 18px; }
#hist-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chip-bar { background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 0 2px; position: sticky; top: 0; z-index: 2; }
.chip-row { display: flex; gap: 6px; overflow-x: auto; padding: 4px 14px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border-radius: 999px; background: #e8ebef; padding: 7px 13px;
  font-size: 13px; font-weight: 600; color: var(--muted); transition: background .12s;
}
.chip.active { background: var(--accent); color: #fff; }
.hist-list { padding: 6px 14px 20px; }
.hist-date { text-align: center; margin: 14px 0 8px; }
.hist-date span { background: #e8ebef; color: var(--muted); font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 3px 12px; }
.hist-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; margin-bottom: 8px;
}
.hist-row.undo .hist-main { opacity: .62; }
.hist-time { color: var(--muted); font-size: 12px; width: 38px; flex-shrink: 0; }
.hist-ava { font-size: 18px; flex-shrink: 0; }
.hist-main { flex: 1; min-width: 0; font-size: 14.5px; }
.hist-main .path { color: var(--muted); }
.hist-ico { font-size: 16px; flex-shrink: 0; }
.hist-more { text-align: center; margin: 4px 0 10px; }
.hist-more button { color: var(--accent-dark); font-weight: 700; padding: 8px 14px; }

/* ---------- Итоги ---------- */
.stat-hero { text-align: center; margin-bottom: 14px; }
.stat-hero .big { font-size: 34px; font-weight: 800; }
.stat-hero .cap { color: var(--muted); font-size: 14px; }
.stat-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: none; }
.stat-name { width: 108px; display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 14.5px; overflow: hidden; white-space: nowrap; }
.stat-track { flex: 1; height: 14px; background: #edf0f3; border-radius: 7px; overflow: hidden; }
.stat-fill { height: 100%; border-radius: 7px; background: linear-gradient(90deg, #34d399, #10b981); transition: width .5s ease; }
.stat-count { width: 56px; text-align: right; font-weight: 800; font-size: 16px; }
.stat-delta { font-size: 11.5px; font-weight: 700; margin-top: 2px; }
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }
.stat-delta.eq { color: var(--muted); }
.streak-pill { background: #fff3e0; color: #c2410c; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 2px 8px; margin-left: 6px; }
.stat-lead { text-align: center; font-weight: 700; color: var(--accent-dark); margin-top: 10px; }

/* ---------- Ещё ---------- */
.more-card { margin-bottom: 14px; }
.more-head { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 10px; }
.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-ava { width: 60px; height: 60px; border-radius: 50%; background: #eef0f3; display: flex; align-items: center; justify-content: center; font-size: 32px; }
.profile-name { font-size: 19px; font-weight: 800; }
.role-badge { display: inline-block; background: #e0e7ff; color: #3730a3; font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 2px 9px; margin-top: 3px; }
.invite-box { display: flex; align-items: center; gap: 10px; }
.invite-code { flex: 1; font-size: 19px; font-weight: 800; letter-spacing: 2px; background: #f6f7f9; border: 1.5px dashed var(--line); border-radius: 12px; padding: 10px 14px; text-align: center; }

.mgmt-zone { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 10px; }
.mgmt-zone-head { display: flex; align-items: center; gap: 8px; }
.mgmt-zone-head .zname { font-weight: 700; flex: 1; }
.mgmt-task { display: flex; align-items: center; gap: 8px; padding: 8px 0 0; border-top: 1px dashed var(--line); margin-top: 8px; }
.mgmt-task .ttitle { flex: 1; font-size: 14.5px; }
.mgmt-task .tperiod { color: var(--muted); font-size: 12.5px; }
.mgmt-task .toff { opacity: .45; text-decoration: line-through; }
.small-btn { padding: 6px 9px; border-radius: 9px; background: #f0f2f5; font-size: 14px; }
.small-btn.danger { background: var(--red-bg); }

.about-note { font-size: 12.5px; color: var(--muted); text-align: center; margin: 6px 0 2px; }

/* Статистика участника (оверлей из «Итогов») */
#ustats-screen {
  position: absolute; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column; animation: slidein .18s ease;
}
#ustats-header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
#ustats-title { font-weight: 700; font-size: 18px; }
#ustats-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.stat-row { cursor: pointer; }

/* Семья (админ) */
.fam-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.fam-row:last-child { border-bottom: none; }
.fam-ava { width: 36px; height: 36px; border-radius: 50%; background: #eef0f3; display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.fam-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Шторка (sheet) ---------- */
#sheet-backdrop {
  position: absolute; inset: 0; z-index: 40; background: rgba(15, 20, 30, .45);
  display: flex; align-items: flex-end; animation: fadein .15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
#sheet {
  background: var(--card); border-radius: 20px 20px 0 0; width: 100%;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheetup .18s ease; max-height: 86%; overflow-y: auto;
}
@keyframes sheetup { from { transform: translateY(40%); } to { transform: none; } }
.sheet-title { font-size: 17px; font-weight: 800; margin-bottom: 12px; }
.sheet-body label { display: block; font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.sheet-body input {
  display: block; width: 100%; margin-top: 4px; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 11px 13px; background: #fafbfc; font-size: 16px;
}
.sheet-body input:focus { outline: none; border-color: var(--accent); background: #fff; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; padding: 12px 8px; }
.sheet-text { font-size: 15px; margin-bottom: 6px; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.emoji-grid button { font-size: 25px; padding: 8px 0; border-radius: 12px; }
.emoji-grid button.sel { background: var(--green-bg); outline: 2px solid var(--accent); }

/* ---------- Игровизация ---------- */
.fam-streak { text-align: center; font-weight: 700; color: #c2410c; margin: 12px 0 2px; font-size: 15px; }
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ach-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 10px; text-align: center; opacity: .45; transition: opacity .3s;
}
.ach-card.on { opacity: 1; }
.ach-icon { font-size: 34px; }
.ach-title { font-weight: 700; font-size: 14px; margin-top: 4px; }
.ach-desc { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.25; }
.ach-who { font-size: 17px; margin-top: 6px; min-height: 22px; }
.my-ach { font-size: 13px; margin-top: 6px; color: var(--muted); }
.my-ach .ach-medal { font-size: 19px; padding: 1px 2px; margin-left: 2px; }

/* Конфетти */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
#confetti i {
  position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px;
  animation: cfall linear forwards;
}
@keyframes cfall { to { transform: translateY(105vh) rotate(720deg); } }

/* ---------- Тосты ---------- */
#toasts {
  position: absolute; left: 0; right: 0; bottom: calc(74px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none;
}
.toast {
  background: #1f242d; color: #fff; border-radius: 14px; padding: 11px 18px; font-size: 14.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 92%; text-align: center;
  animation: toastin .2s ease;
}
.toast.good { background: #0c7a55; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Графические аватары ---------- */
img.ava-img { vertical-align: middle; }
/* чат и профиль — портрет в круге (намеренно, как в мессенджере) */
.chat-ava { width: 36px; height: 36px; font-size: 18px; }
.chat-ava img.ava-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-ava img.ava-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
/* списки — без кружка, на прозрачном фоне, как эмодзи */
.fam-ava { width: 40px; height: 40px; font-size: 22px; background: none; }
.fam-ava img.ava-img { width: 100%; height: 100%; object-fit: contain; }
.hist-ava img.ava-img { width: 27px; height: 27px; object-fit: contain; }
.stat-name img.ava-img { width: 31px; height: 31px; object-fit: contain; flex-shrink: 0; }
.stat-lead img.ava-img { width: 24px; height: 24px; object-fit: contain; vertical-align: -6px; }
.ach-who img.ava-img { width: 29px; height: 29px; object-fit: contain; margin: 0 1px; }
#ustats-title img.ava-img { width: 28px; height: 28px; object-fit: contain; vertical-align: -7px; margin-right: 3px; }
.stat-name { gap: 8px; }
.emoji-grid.custom { grid-template-columns: repeat(3, 1fr); }
.emoji-grid.custom button { padding: 4px 0; }
.emoji-grid.custom button img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto; }
