@font-face {
  font-family: "Onest";
  src: url("vendor/onest-cyrillic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Onest";
  src: url("vendor/onest-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+20AC, U+2122, U+2212;
}

:root,
[data-theme="dark"] {
  --bg: #090d16;
  --card: rgba(22, 31, 48, 0.7);
  --card-solid: #141c2c;
  --line: rgba(255, 255, 255, 0.08);
  --field: rgba(255, 255, 255, 0.05);
  --track: rgba(255, 255, 255, 0.07);
  --ink: #f4f6fb;
  --muted: #94a0b5;
  --danger: #f87171;
  --tasks-ink: #a78bfa;
  --food-ink: #34d399;
  --water-ink: #22d3ee;
  --ai-ink: #fbbf24;
  --glow-a: rgba(139, 92, 246, 0.16);
  --glow-b: rgba(6, 182, 212, 0.1);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef1f7;
  --card: rgba(255, 255, 255, 0.78);
  --card-solid: #ffffff;
  --line: rgba(15, 23, 42, 0.1);
  --field: rgba(15, 23, 42, 0.05);
  --track: rgba(15, 23, 42, 0.08);
  --ink: #111827;
  --muted: #566176;
  --danger: #c62828;
  --tasks-ink: #6d28d9;
  --food-ink: #047857;
  --water-ink: #0e7490;
  --ai-ink: #b45309;
  --glow-a: rgba(139, 92, 246, 0.12);
  --glow-b: rgba(6, 182, 212, 0.12);
  color-scheme: light;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(90% 50% at 90% 0%, var(--glow-a), transparent 70%),
    radial-gradient(80% 45% at 0% 70%, var(--glow-b), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

i[data-lucide],
svg.lucide {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.shell {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--app-height, 100dvh);
  transform: translateY(var(--app-top, 0px));
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px) + 14px) 16px 20px;
  scrollbar-width: none;
}

.view::-webkit-scrollbar {
  display: none;
}

.view.is-chat {
  display: flex;
  flex-direction: column;
  /* Отступы переехали в шапку и поле ввода, иначе сообщения видны в зазорах вокруг них. */
  padding-top: 0;
  padding-bottom: 0;
}

/* --- Навигация --- */

.nav {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 8px calc(max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px)) + 6px);
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.nav.is-hidden {
  display: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 48px;
  padding: 6px 2px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s, background-color 0.15s;
}

.nav-item[aria-current="page"] {
  color: var(--accent);
  background: var(--field);
}

/* --- Карточки --- */

.card {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.big-number {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

/* --- Кольца --- */

.hero {
  border-radius: 30px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rings {
  position: relative;
  width: min(40vw, 160px);
  aspect-ratio: 1;
  flex: none;
}

.rings svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.rings circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring-track {
  stroke: var(--track);
}

.ring-value {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s;
}

.rings-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  margin-top: 5px;
}

/* --- Вода поднимается внутри карточки --- */

.water-card {
  isolation: isolate;
}

.water-level {
  position: absolute;
  inset: auto 0 0 0;
  height: calc(var(--level, 0) * 1%);
  min-height: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.34), rgba(6, 182, 212, 0.14));
  transition: height 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.water-level::before {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  top: -7px;
  height: 14px;
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.28);
}

.water-level.is-empty::before {
  display: none;
}

/* --- Кнопки и поля --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
}

.btn svg.lucide {
  width: 17px;
  height: 17px;
}

.btn-food {
  background: #10b981;
  color: #04130d;
}

.btn-tasks {
  background: #8b5cf6;
  color: #fff;
}

.btn-ai {
  background: #f59e0b;
  color: #1c1303;
}

.btn-water {
  background: rgba(6, 182, 212, 0.2);
  color: var(--water-ink);
}

.btn-quiet {
  background: var(--field);
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 14px;
  color: var(--muted);
}

.icon-btn:disabled {
  opacity: 0.35;
}

.field {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--ink);
  /* 16px не даёт iOS приближать экран при фокусе */
  font-size: 16px;
  outline: none;
}

.field::placeholder {
  color: var(--muted);
  opacity: 1;
}

.field:focus {
  border-color: var(--muted);
}

textarea.field {
  resize: none;
  display: block;
}

.label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 14px;
  background: var(--field);
}

.segmented button {
  flex: 1;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.segmented button[aria-pressed="true"] {
  background: var(--card-solid);
  color: var(--ink);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--field);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.chip-button {
  min-height: 34px;
  padding: 4px 12px;
  font-size: 13px;
}

.chip-button[aria-pressed="true"] {
  background: var(--tasks-ink);
  color: var(--bg);
}

.chips-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips-row::-webkit-scrollbar {
  display: none;
}

/* --- Строки списков --- */

.row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  border-top: 1px solid var(--line);
}

.row:first-child {
  border-top: 0;
}

.row-main {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  text-align: left;
}

.row-title {
  overflow-wrap: anywhere;
}

.check {
  width: 44px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: -10px;
}

.check span {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: 2px solid var(--muted);
  color: #fff;
  transition: background-color 0.15s, border-color 0.15s;
}

.check svg.lucide {
  width: 15px;
  height: 15px;
  stroke-width: 3;
  opacity: 0;
}

.check[aria-checked="true"] span {
  background: #8b5cf6;
  border-color: #8b5cf6;
}

.check[aria-checked="true"] svg.lucide {
  opacity: 1;
}

.is-done .row-title {
  color: var(--muted);
  text-decoration: line-through;
}

.note-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #10b981;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar.is-over span {
  background: var(--danger);
}

/* --- Чат --- */

.chat-header {
  position: sticky;
  top: 0;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 -16px;
  padding: calc(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px) + 6px) 8px 6px;
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.chat-exit {
  color: var(--ink);
}

.chat-exit svg.lucide {
  width: 26px;
  height: 26px;
}

.chat-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
}

.bubble {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble code {
  padding: 0 4px;
  border-radius: 5px;
  background: var(--field);
  font-size: 0.92em;
}

.bubble-user {
  align-self: flex-end;
  background: #f59e0b;
  color: #1c1303;
  border-bottom-right-radius: 6px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 14px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  position: sticky;
  bottom: 0;
  flex: none;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 0 -16px;
  padding: 8px 16px;
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

/* Поле не должно прилипать к самому краю панели, когда браузер прокручивает к нему. */
.field {
  scroll-margin: 16px;
}

.send-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: #f59e0b;
  color: #1c1303;
}

.send-btn:disabled {
  opacity: 0.5;
}

.spinner {
  width: 17px;
  height: 17px;
  flex: none;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Нижняя панель --- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(3, 6, 12, 0.6);
  animation: fade 0.18s ease-out;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  top: auto;
  bottom: var(--keyboard-offset, 0px);
  z-index: 31;
  max-height: calc(var(--app-height, 100dvh) * 0.9);
  overflow-y: auto;
  padding: 18px 16px calc(max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px)) + 16px);
  background: var(--card-solid);
  border-top: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  animation: rise 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fade {
  from { opacity: 0; }
}

@keyframes rise {
  from { transform: translateY(24px); opacity: 0.4; }
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px) + 12px);
  z-index: 40;
  padding: 11px 14px;
  border-radius: 14px;
  background: var(--card-solid);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast.is-error {
  border-color: var(--danger);
}

.skeleton {
  border-radius: 22px;
  background: var(--field);
  animation: pulse 1.3s infinite ease-in-out;
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

.preview-photo {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 18px;
}

/* --- Фото --- */

.photo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-strip[hidden] {
  display: none;
}

.photo-tile {
  position: relative;
  width: 76px;
  height: 76px;
  flex: none;
}

.photo-tile button:first-child {
  display: block;
  width: 100%;
  height: 100%;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
  background: var(--field);
}

.photo-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--card-solid);
  border: 1px solid var(--line);
  color: var(--ink);
}

.photo-remove svg.lucide {
  width: 14px;
  height: 14px;
}

.note-photos {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}

.note-photos img {
  width: 72px;
  height: 72px;
  flex: none;
  object-fit: cover;
  border-radius: 12px;
  background: var(--field);
}

.chip-photo {
  gap: 3px;
}

.chip-photo svg.lucide {
  width: 12px;
  height: 12px;
}

.bubble-photo {
  display: block;
  margin-bottom: 6px;
}

.bubble-photo:last-child {
  margin-bottom: 0;
}

.bubble-photo img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  min-width: 80px;
  min-height: 60px;
  object-fit: cover;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.15);
}

.attach-btn {
  width: 36px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--muted);
}

.composer {
  flex-wrap: wrap;
}

.composer textarea.field {
  flex: 1;
  width: auto;
  min-width: 0;
}

.scan-comment {
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--field);
  white-space: pre-wrap;
}

.scan-comment[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.92);
  animation: fade 0.15s ease-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* --- Встроенная камера --- */

.camera {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
}

.camera video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera video[hidden] {
  display: none;
}

.camera-error {
  max-width: 320px;
  padding: 0 24px;
  text-align: center;
}

.camera-error[hidden] {
  display: none;
}

.camera-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px calc(max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px)) + 24px);
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.6));
}

.camera-side {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.camera-shutter {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 255, 255, 0.45);
  background-clip: padding-box;
}

.camera-shutter:active {
  transform: scale(0.94);
}

.camera-shutter:disabled {
  opacity: 0.4;
}

.camera-shutter[hidden] {
  visibility: hidden;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
