:root {
  --bg: linear-gradient(160deg, #fff4ec 0%, #f4f0ff 100%);
  --bg-solid: #fff4ec;
  --surface: #ffffff;
  --surface-2: #f5f2fa;
  --text: #1f1d2b;
  --muted: #8a8698;
  --accent: #ff7a59;
  --accent-soft: #ffe8e0;
  --danger: #e5484d;
  --danger-soft: #fdeaea;
  --good: #23995e;
  --good-soft: #e1f5ea;
  --warn: #c7761a;
  --warn-soft: #fdf0de;
  --border: rgba(31, 29, 43, 0.08);
  --shadow: 0 2px 12px rgba(31, 29, 43, 0.07);
}
[data-theme="dark"] {
  --bg: linear-gradient(160deg, #1c1a29 0%, #131219 100%);
  --bg-solid: #1c1a29;
  --surface: #25232f;
  --surface-2: #2e2c3b;
  --text: #f1eff7;
  --muted: #9b97ac;
  --accent: #ff8a6b;
  --accent-soft: rgba(255, 138, 107, 0.16);
  --danger: #ff6b6f;
  --danger-soft: rgba(255, 107, 111, 0.16);
  --good: #4cd08a;
  --good-soft: rgba(76, 208, 138, 0.15);
  --warn: #f2a54a;
  --warn-soft: rgba(242, 165, 74, 0.15);
  --border: rgba(255, 255, 255, 0.07);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
/* Атрибут hidden завжди ховає елемент, навіть якщо в класу є display: flex */
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  padding: 20px 16px 96px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg) fixed;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; border: 0; }

header { margin-bottom: 18px; }
#hello { font-size: 24px; font-weight: 700; margin: 0; }
.subtitle { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* Вкладки */
.tabs, .seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 14px;
}
.tabs { margin-bottom: 18px; }
.seg { margin-bottom: 12px; border-radius: 12px; padding: 3px; }
.tabs button, .seg button {
  flex: 1; padding: 9px 4px; border-radius: 11px; font-weight: 600; font-size: 14px;
  background: transparent; color: var(--muted); transition: all .2s; white-space: nowrap;
}
.seg button { padding: 8px; border-radius: 9px; }
.tabs button.bug-tab { flex: 0 0 auto; padding: 9px 10px; }
/* П'ять вкладок на вузькому телефоні: стискаємо підписи, щоб 🐞 не виїжджала за край екрана */
.tabs button { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 400px) {
  .tabs { gap: 2px; }
  .tabs button { font-size: 13px; padding: 9px 2px; }
  .tabs button.bug-tab { padding: 9px 6px; }
  .tabs .badge { margin-left: 2px; padding: 1px 4px; min-width: 14px; }
}
.tabs button.active, .seg button.active {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.badge {
  display: inline-block; min-width: 18px; padding: 1px 5px; margin-left: 3px;
  border-radius: 10px; font-size: 11px; background: var(--accent); color: #fff;
}
.badge:empty { display: none; }

/* Поле додавання */
.add {
  display: flex; gap: 8px; padding: 6px; margin-bottom: 14px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
.add input {
  flex: 1; min-width: 0; padding: 10px 12px; font-size: 16px;
  border: 0; outline: 0; background: transparent; color: var(--text);
}
.add input::placeholder { color: var(--muted); }
.add button {
  width: 44px; height: 44px; border-radius: 12px; font-size: 24px; line-height: 1;
  background: var(--accent); color: #fff;
}

/* Рядки покупок і складу */
ul { list-style: none; padding: 0; margin: 0; }
.row, .card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.row label, .row .line { display: flex; align-items: center; gap: 12px; padding: 12px 14px; font-size: 16px; }
.row-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row.done .row-title { text-decoration: line-through; color: var(--muted); }
.qty { color: var(--muted); font-size: 14px; padding-left: 4px; white-space: nowrap; }

.check {
  appearance: none; -webkit-appearance: none; margin: 0; flex-shrink: 0;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--accent); transition: background-color .15s;
}
.check:checked {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 13px no-repeat;
}

.link-btn {
  display: block; width: 100%; padding: 12px; margin-top: 6px;
  background: transparent; color: var(--accent); font-weight: 600;
}

/* Фільтри записів */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: 20px; font-size: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.chip.active { background: var(--accent); color: #fff; }
.filters { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 14px; }
select {
  width: 100%; padding: 9px 10px; font-size: 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

/* Картки записів */
.card { position: relative; padding: 14px 14px 12px 18px; overflow: hidden; }
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: var(--type-color, var(--accent));
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-type { font-size: 13px; color: var(--muted); }
.card-title { font-size: 16px; font-weight: 600; margin-top: 4px; }
.card-details { font-size: 14px; font-weight: 600; margin-top: 6px; }
.card-link { display: block; margin-top: 6px; padding: 0; text-align: left; font-size: 13px; }
.card-source { margin-top: 6px; font-size: 13px; color: var(--muted); }
.event-block { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.event-who { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.event-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.event-actions .primary, .event-actions .secondary { flex: 0 0 auto; width: auto; padding: 8px 12px; font-size: 14px; }
.event-actions .link-small { font-size: 13px; }
#calendar-sub { margin-bottom: 12px; }
.card.past { opacity: .55; }
.card.past .card-details::after { content: " · минула"; font-weight: 400; color: var(--muted); }
.card-body { font-size: 14px; margin-top: 6px; white-space: pre-wrap; opacity: .85; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); margin-top: 10px; }

.actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn, .del {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 16px; flex-shrink: 0;
}
.icon-btn { background: var(--surface-2); color: var(--text); }
.del { background: var(--danger-soft); color: var(--danger); }
.icon-btn:active, .del:active { transform: scale(.92); }

/* Рецепти */
.recipe { padding: 0; }
.recipe::before { background: #4cc985; }
.recipe-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 14px 18px; width: 100%; background: transparent; color: inherit; text-align: left; }
.recipe-head .row-text { gap: 4px; }
.recipe-title { font-size: 16px; font-weight: 600; }
.recipe-sub { font-size: 13px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 10px; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.chevron { color: var(--muted); transition: transform .2s; flex-shrink: 0; }
.recipe.open .chevron { transform: rotate(180deg); }
.recipe-body { padding: 0 14px 14px 18px; display: none; }
.recipe.open .recipe-body { display: block; }
.recipe-body h4 { margin: 14px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.ing { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.ing:last-child { border-bottom: 0; }
.ing-mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.ing-mark.have { background: var(--good-soft); color: var(--good); }
.ing-mark.miss { background: var(--danger-soft); color: var(--danger); }
.ing-mark.staple, .ing-mark.optional { background: var(--surface-2); color: var(--muted); }
.ing.optional .ing-name { color: var(--muted); }
.recipe-note { font-size: 13px; color: var(--muted); margin-top: 12px; }
#recipe-cats { margin-top: -6px; margin-bottom: 14px; }
.ing-name { flex: 1; min-width: 0; }
.ing.miss .ing-name { color: var(--danger); }
.ing-amount { color: var(--muted); font-size: 14px; white-space: nowrap; }
.steps { margin: 0; padding-left: 22px; }
.steps li { margin-bottom: 8px; line-height: 1.45; font-size: 15px; }
.recipe-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.primary {
  flex: 1; padding: 12px; border-radius: 12px; font-weight: 600;
  background: var(--accent); color: #fff;
}
.all-good { flex: 1; padding: 12px; border-radius: 12px; text-align: center; font-weight: 600; background: var(--good-soft); color: var(--good); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.empty div { font-size: 40px; margin-bottom: 8px; }
.empty small { display: block; margin-top: 6px; font-size: 13px; }

@keyframes flash {
  0%, 100% { box-shadow: var(--shadow); }
  30%, 70% { box-shadow: 0 0 0 3px var(--accent); }
}
.flash { animation: flash 1.4s ease; }

/* Рецепти: пошук і підбір */
.discover {
  padding: 14px; margin-bottom: 18px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  box-shadow: var(--shadow);
}
.discover-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.discover-sub { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.discover .add { margin-bottom: 8px; box-shadow: none; }
.secondary {
  width: 100%; padding: 11px; border-radius: 12px; font-weight: 600; font-size: 15px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.secondary:disabled, .primary:disabled { opacity: .6; }
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 2px 10px; font-weight: 700; font-size: 17px;
}
.link-small { background: transparent; color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px; }
.search-row { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; }
.search-row .chip { padding: 11px 12px; white-space: nowrap; }
.ai-offer {
  margin-top: 4px; padding: 14px; border-radius: 16px; text-align: center;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface)); box-shadow: var(--shadow);
}
.ai-offer p { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.ai-offer .primary { width: 100%; }
.search-row input {
  flex: 1; min-width: 0;
  padding: 11px 14px; font-size: 15px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: 0;
}
.search-row input::placeholder { color: var(--muted); }
.recipe.idea::before { background: var(--accent); }
.loading { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 10px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#ideas-block { margin-bottom: 20px; }

/* Гроші */
.pos { color: var(--good); }
.neg { color: var(--danger); }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav button {
  width: 40px; height: 40px; border-radius: 12px; font-size: 22px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.month-nav button:disabled { opacity: .35; }
#month-label { font-weight: 700; font-size: 17px; }
.money-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.money-card {
  padding: 12px 10px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.money-card span { font-size: 12px; color: var(--muted); }
.money-card b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.money-form {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; margin-top: 8px;
  border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
}
.money-form .seg { margin-bottom: 0; }
.money-row { display: flex; gap: 8px; align-items: center; }
.money-form input[type=text], .money-form input[type=date], .cart-expense input {
  flex: 1; min-width: 0; padding: 10px 12px; font-size: 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: 0;
}
.money-form select { flex: 1; min-width: 0; }
.check-label { display: flex; align-items: center; gap: 6px; font-size: 15px; white-space: nowrap; }
.check-label input { width: 18px; height: 18px; }
#m-toggle-form { margin-bottom: 4px; }
#m-cats-block { margin-top: 18px; }
.cat-row { padding: 10px 14px; margin-bottom: 6px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.cat-line { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.cat-line b { white-space: nowrap; }
.cat-bar { height: 6px; margin-top: 8px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cat-bar div { height: 100%; border-radius: 3px; background: var(--accent); }
.day-head { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 4px 6px; }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left;
      border-radius: 14px; margin-bottom: 6px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.tx-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
           background: var(--surface-2); font-size: 18px; flex-shrink: 0; }
.tx-amount { font-weight: 700; white-space: nowrap; }
.money-compare { font-size: 13px; color: var(--muted); margin: -4px 2px 12px; }
.money-form-title { font-weight: 700; }
.budget-form { margin: 0 0 10px; }
.cat-row { cursor: pointer; }
.cat-row.over .cat-bar div { background: var(--danger); }
.cat-row.over .cat-line b { color: var(--danger); }
.cat-limit { font-size: 12px; color: var(--muted); margin-top: 6px; }
.cat-edit { display: flex; gap: 8px; margin-top: 10px; }
.cat-edit input {
  flex: 1; min-width: 0; padding: 9px 12px; font-size: 16px; border-radius: 12px; outline: 0;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.cat-edit .primary { flex: 0 0 auto; padding: 9px 14px; }
.tx-day { font-size: 12px; color: var(--muted); }
/* Баги */
.bug-form { margin-bottom: 16px; }
.bug-form textarea {
  width: 100%; min-height: 84px; padding: 12px; font: inherit; font-size: 16px; resize: vertical;
  border-radius: 12px; border: 1px solid var(--border); outline: 0; background: var(--surface-2); color: var(--text);
}
#bug-preview { position: relative; }
#bug-img { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
#bug-img-remove { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; font-size: 12px; }
#bug-copy { margin-bottom: 12px; }
.bug-card { padding: 14px; }
.bug-card.sev-critical::before { background: var(--danger); }
.bug-card.sev-major::before { background: #ffb547; }
.bug-card.sev-minor::before { background: var(--good); }
.bug-text { font-size: 15px; margin-top: 6px; white-space: pre-wrap; }
.bug-ctx { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
           font-size: 13px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.bug-ctx b { color: var(--text); font-weight: 600; }
.bug-shot { display: block; max-width: 100%; max-height: 260px; margin-top: 10px; border-radius: 12px; border: 1px solid var(--border); }
#bug-export { width: 100%; min-height: 160px; margin-bottom: 12px; padding: 10px; font-size: 13px;
              border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.cart-expense { padding: 12px; margin-top: 10px; border-radius: 16px; background: var(--accent-soft); }
.cart-expense-title { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.cart-expense .primary { flex: 0 0 auto; padding: 10px 14px; }

/* Помічник */
#fab {
  position: fixed; right: 16px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 24px;
  box-shadow: 0 6px 20px rgba(255, 122, 89, .45); z-index: 10;
}
#fab:active { transform: scale(.94); }
#sheet-backdrop, #cook-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
#sheet, .bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 85vh; overflow-y: auto;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  transform: translateY(105%); visibility: hidden;
  transition: transform .25s ease, visibility 0s linear .25s;
}
#sheet.open, .bottom-sheet.open { transform: translateY(0); visibility: visible; transition: transform .25s ease; }

/* Приготували і замовлення */
#cook-list { margin: 8px 0 12px; }
.cook-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--border); font-size: 15px; }
.cook-item:last-child { border-bottom: 0; }
.cook-item .row-text { flex: 1; }
.cook-cart { margin-bottom: 12px; }
#cook-done { width: 100%; }
.recipe-actions2 { display: flex; gap: 8px; margin-top: 8px; }
.recipe-actions2 .secondary { flex: 1; padding: 10px 6px; font-size: 14px; }
.order-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.order-form input {
  padding: 10px 12px; font-size: 16px; border-radius: 12px; outline: 0;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.order-card { padding: 14px; }
.order-card::before { background: #ffb547; }
.order-actions { display: flex; gap: 8px; margin-top: 12px; }
.order-actions button { flex: 1; padding: 10px 6px; font-size: 14px; }
.order-actions .del { flex: 0 0 40px; height: 40px; padding: 0; align-self: center; }
.pill.muted { background: var(--surface-2); color: var(--muted); }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
.sheet-title { font-weight: 700; font-size: 18px; }
.sheet-usage { font-size: 12px; color: var(--muted); margin: -6px 0 10px; white-space: pre-line; }
.sheet-sub { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
#ask {
  width: 100%; min-height: 84px; padding: 12px; font: inherit; font-size: 16px; resize: vertical;
  border-radius: 14px; border: 1px solid var(--border); outline: 0;
  background: var(--surface-2); color: var(--text);
}
#ask-examples { margin: 10px 0 12px; }
.ask-tools { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.ask-tools label.chip { cursor: pointer; background: var(--surface-2); box-shadow: none; }
#ask-preview { position: relative; }
#ask-img { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
#ask-img-remove { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; font-size: 12px; }
#ask-examples .chip { box-shadow: none; background: var(--surface-2); font-size: 13px; }
#ask-send { width: 100%; }
#ask-result {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); font-size: 15px; line-height: 1.45;
}
#ask-text { white-space: pre-wrap; }
#ask-undo { padding: 8px 0 0; text-align: left; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: 92px; z-index: 30; padding: 14px 16px;
  border-radius: 14px; background: var(--text); color: var(--bg-solid);
  font-size: 15px; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(20px); pointer-events: none; transition: all .25s;
}
#toast.show { opacity: 1; transform: translateY(0); }
