/* =====================================================================
   Chores — дизайн-система
   Світла тема за замовчуванням, темна — за перемикачем або системою.
   ===================================================================== */

:root {
  /* Кольори */
  --bg:            #f6f7fb;
  --bg-elevated:   #ffffff;
  --bg-sunken:     #eef0f6;
  --surface:       #ffffff;
  --surface-2:     #f2f4f9;
  --border:        #e3e7ef;
  --border-strong: #cfd6e4;

  --text:          #131722;
  --text-muted:    #626b7e;
  --text-faint:    #8b94a7;

  --accent:        #4f7df3;
  --accent-soft:   #e8effe;
  --accent-strong: #3563d6;
  --success:       #17a673;
  --success-soft:  #e2f6ee;
  --warn:          #e8952f;
  --warn-soft:     #fdf1e0;
  --danger:        #e2544c;
  --danger-soft:   #fdeceb;

  /* Форма */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-full: 999px;

  --shadow-1: 0 1px 2px rgba(19, 23, 34, .05), 0 1px 3px rgba(19, 23, 34, .04);
  --shadow-2: 0 4px 12px rgba(19, 23, 34, .07), 0 2px 4px rgba(19, 23, 34, .04);
  --shadow-3: 0 18px 40px rgba(19, 23, 34, .16);

  --ease: cubic-bezier(.32, .72, 0, 1);
  --tap: rgba(79, 125, 243, .12);

  --header-h: 56px;
  --tabbar-h: 62px;

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:            #0e1117;
  --bg-elevated:   #161a23;
  --bg-sunken:     #0a0d12;
  --surface:       #161a23;
  --surface-2:     #1d222d;
  --border:        #262c39;
  --border-strong: #333b4b;

  --text:          #e8ebf2;
  --text-muted:    #9aa3b5;
  --text-faint:    #6d7689;

  --accent:        #6f95f7;
  --accent-soft:   #1c2740;
  --accent-strong: #8aa9f9;
  --success:       #2fbd8b;
  --success-soft:  #142a23;
  --warn:          #f0a94a;
  --warn-soft:     #2c2115;
  --danger:        #f06a62;
  --danger-soft:   #2e1917;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 6px 16px rgba(0, 0, 0, .45);
  --shadow-3: 0 20px 44px rgba(0, 0, 0, .6);
  --tap: rgba(111, 149, 247, .16);

  color-scheme: dark;
}

/* ── Базове ─────────────────────────────────────────────────────── */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .25s var(--ease), color .25s var(--ease);
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p  { margin: 0 0 10px; }
a  { color: var(--accent); text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }
input, textarea, select { -webkit-appearance: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.hidden, [hidden] { display: none !important; }
.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.small  { font-size: 13px; }
.tiny   { font-size: 12px; }
.center { text-align: center; }
.row    { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.col    { display: flex; flex-direction: column; gap: 10px; }
.grow   { flex: 1; min-width: 0; }
.wrap   { flex-wrap: wrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Каркас застосунку ──────────────────────────────────────────── */

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.appbar h1 { font-size: 20px; }

.view {
  flex: 1;
  padding: 14px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  animation: view-in .28s var(--ease);
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Нижня навігація ────────────────────────────────────────────── */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 550;
  position: relative;
  transition: color .18s var(--ease);
}

.tabbar a.active { color: var(--accent); }
.tabbar a.active .ico { transform: translateY(-1px) scale(1.06); }
.tabbar .ico { transition: transform .25s var(--ease); }

.tabbar .badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 6px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  animation: pop .3s var(--ease);
}

@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Картки ─────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: var(--shadow-1);
}

.card + .card { margin-top: 10px; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 2px 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ── Завдання ───────────────────────────────────────────────────── */

.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  margin-bottom: 8px;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), opacity .25s var(--ease);
  animation: item-in .3s var(--ease) backwards;
}

.task:active { transform: scale(.985); }
.task.done   { opacity: .55; }
.task.done .task-title { text-decoration: line-through; }
.task.overdue { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }

@keyframes item-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.check {
  flex: none;
  width: 26px;
  height: 26px;
  margin-top: 1px;
  border-radius: var(--r-full);
  border: 2px solid var(--border-strong);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all .2s var(--ease);
}

.check svg { width: 14px; height: 14px; opacity: 0; transform: scale(.5); transition: all .2s var(--ease); stroke: #fff; }
.check.on { background: var(--success); border-color: var(--success); }
.check.on svg { opacity: 1; transform: none; }
.check:active { transform: scale(.88); }

.task-title { font-weight: 550; line-height: 1.35; }

.task-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 550;
  color: var(--text-muted);
  white-space: nowrap;
}

.chip.accent  { background: var(--accent-soft);  color: var(--accent-strong); }
.chip.success { background: var(--success-soft); color: var(--success); }
.chip.warn    { background: var(--warn-soft);    color: var(--warn); }
.chip.danger  { background: var(--danger-soft);  color: var(--danger); }

.avatar {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  object-fit: cover;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }

/* ── Кнопки ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s var(--ease), background .2s var(--ease), opacity .2s;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn.soft  { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; }

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .18s var(--ease), transform .15s var(--ease);
}

.icon-btn:hover { background: var(--surface-2); }

.icon-btn .badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.icon-btn:active { transform: scale(.9); }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 45;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .2s var(--ease);
}

.fab:active { transform: scale(.92) rotate(90deg); }

/* ── Поля ───────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }

.input, textarea.input, select.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}

.input:focus, textarea.input:focus, select.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--tap);
}

textarea.input { min-height: 90px; resize: vertical; line-height: 1.5; }

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b94a7' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }

/* Сам чекбокс лишається в DOM (доступний з клавіатури), але невидимий */
.switch input {
  position: absolute;
  left: 0;
  width: 46px;
  height: 28px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--tap); }

.switch .track {
  width: 46px;
  height: 28px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  position: relative;
  transition: background .22s var(--ease);
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: var(--r-full);
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform .22s var(--ease);
}

.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* Сегментований перемикач */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
}

.segmented button {
  flex: 1;
  min-height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s var(--ease);
}

.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* Дні тижня */
.weekdays { display: flex; gap: 6px; }
.weekdays button {
  flex: 1;
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  transition: all .18s var(--ease);
}
.weekdays button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Модальні вікна / шторка ────────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 13, 18, .45);
  backdrop-filter: blur(2px);
  animation: fade-in .2s var(--ease);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 91;
  max-height: 92vh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg-elevated);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-3);
  animation: sheet-up .32s var(--ease);
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

.sheet .grabber {
  width: 38px;
  height: 4px;
  margin: 6px auto 14px;
  border-radius: var(--r-full);
  background: var(--border-strong);
}

@media (min-width: 720px) {
  .sheet {
    left: 50%;
    bottom: auto;
    top: 50%;
    width: 560px;
    transform: translate(-50%, -50%);
    border-radius: var(--r-lg);
    animation: dialog-in .28s var(--ease);
  }
  @keyframes dialog-in {
    from { opacity: 0; transform: translate(-50%, -46%) scale(.97); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
  }
}

/* ── Тости ──────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(94vw, 420px);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--r-sm);
  background: #1b2130;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-2);
  animation: toast-in .28s var(--ease);
}

html[data-theme="dark"] .toast { background: #2a3140; }
.toast.err { background: var(--danger); }
.toast.ok  { background: var(--success); }

@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }

/* ── Чат ────────────────────────────────────────────────────────── */

.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg { display: flex; gap: 8px; max-width: 84%; animation: item-in .25s var(--ease); }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }

.msg .bubble {
  padding: 9px 13px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.45;
  word-break: break-word;
}

.msg.mine .bubble { background: var(--accent); border-color: var(--accent); color: #fff; }
.msg .author { font-size: 11.5px; font-weight: 650; margin-bottom: 2px; opacity: .8; }
.msg .time   { font-size: 10.5px; opacity: .6; margin-top: 3px; }

.msg.system {
  align-self: center;
  max-width: 90%;
  font-size: 12.5px;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 6px 12px;
  border-radius: var(--r-full);
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.chat-input textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--bg);
  resize: none;
}

/* ── Статистика ─────────────────────────────────────────────────── */

.bar {
  height: 8px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width .6s var(--ease);
}

.heat {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13px, 1fr));
  gap: 4px;
}

.heat i {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--surface-2);
}

.heat i[data-l="1"] { background: color-mix(in srgb, var(--success) 30%, var(--surface-2)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--success) 55%, var(--surface-2)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--success) 80%, var(--surface-2)); }
.heat i[data-l="4"] { background: var(--success); }

/* ── Порожні стани і скелетони ──────────────────────────────────── */

.empty {
  padding: 46px 20px;
  text-align: center;
  color: var(--text-faint);
}

.empty .ico { opacity: .35; margin-bottom: 12px; }

.skeleton {
  height: 62px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.3s infinite linear;
  margin-bottom: 8px;
}

@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -150% 0; } }

/* ── Іконки ─────────────────────────────────────────────────────── */

.ico {
  width: 22px;
  height: 22px;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.ico.sm { width: 17px; height: 17px; }
.ico.lg { width: 30px; height: 30px; }
.ico.xl { width: 44px; height: 44px; }

/* ── Офлайн-плашка ──────────────────────────────────────────────── */

.offline-bar {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0; right: 0;
  z-index: 100;
  padding: 7px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--warn);
  color: #241703;
  animation: item-in .25s var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
