:root {
  --green: #2E7D32;
  --green-dark: #1B5E20;
  --green-light: #E8F5E9;
  --bg: #F6F8F6;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --muted: #6B7A6E;
  --line: #E0E6E1;
  --red: #C62828;
  --amber: #F9A825;
  --radius: 14px;
  --shadow: 0 1px 4px rgba(27, 94, 32, 0.10);
}

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

/* Атрибут hidden обязан побеждать любые display-правила ниже */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Верхняя панель ─────────────────────────── */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--green);
  color: #fff;
}
#topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.usage-badge {
  font-size: 12px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ── Контент ────────────────────────────────── */
.view {
  flex: 1;
  padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card h2 { font-size: 16px; margin: 0 0 8px; }
.card h3 { font-size: 14px; margin: 12px 0 6px; color: var(--green-dark); }

.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.center { text-align: center; }
.mt { margin-top: 12px; }

/* ── Списки культур ─────────────────────────── */
.culture-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.culture-item:last-child { border-bottom: none; }
.culture-emoji {
  width: 42px; height: 42px;
  flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--green-light);
  border-radius: 12px;
  font-size: 22px;
}
.culture-name { font-weight: 600; }
.culture-sub { font-size: 12px; color: var(--muted); }

/* ── Кнопки ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  width: 100%;
}
.btn:active { background: var(--green-dark); }
.btn.secondary {
  background: var(--green-light);
  color: var(--green-dark);
}
.btn.danger { background: var(--red); }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 15;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(27,94,32,.35);
  cursor: pointer;
}

/* ── Табы ───────────────────────────────────── */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ── Формы ──────────────────────────────────── */
.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 5px;
}
input[type="text"], input[type="date"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

/* Поле даты: показываем дд.мм.гггг своей надписью, поверх — прозрачный
   нативный календарь (тап открывает системный пикер) */
.datefield {
  position: relative;
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  cursor: pointer;
}
.datefield-value.empty { color: var(--muted); }
.datefield-value { display: block; padding-right: 32px; }
.datefield-ico {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 16px;
}
.datefield:focus-within {
  outline: 2px solid var(--green);
  border-color: var(--green);
}
.datefield input[type="date"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green); border-color: var(--green); }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 15px;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--green); }

/* ── Задачи ─────────────────────────────────── */
.task {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: none; }
.task input[type="checkbox"] { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--green); }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 600; font-size: 15px; }
.task-desc { font-size: 13px; color: var(--muted); }
.task-date {
  flex: none;
  font-size: 11px;
  background: var(--green-light);
  color: var(--green-dark);
  border-radius: 6px;
  padding: 2px 7px;
  margin-top: 2px;
  white-space: nowrap;
}

/* ── Markdown-ответы AI ─────────────────────── */
.md h2 {
  font-size: 16px;
  color: var(--green-dark);
  border-bottom: 2px solid var(--green-light);
  padding-bottom: 4px;
  margin: 18px 0 8px;
}
.md h3 { font-size: 14px; margin: 12px 0 6px; }
.md p { margin: 8px 0; line-height: 1.55; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 4px 0; line-height: 1.5; }
.md strong { color: var(--green-dark); }
.md code { background: var(--green-light); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ── Фото ───────────────────────────────────── */
.photo-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
  display: none;
}
.photo-preview.visible { display: block; }

/* ── Нижняя навигация ───────────────────────── */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0 6px;
  text-decoration: none;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
}
.bottomnav a.active { color: var(--green); }
.nav-ico { font-size: 21px; line-height: 1; height: 24px; display: flex; align-items: center; justify-content: center; }
.nav-ico svg { display: block; }
.culture-emoji svg { display: block; }
.empty .big svg { display: block; margin: 0 auto 10px; color: var(--green); opacity: 0.55; }

/* ── Тамагочи ─────────────────────────────── */
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}
.ach-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green-dark);
  background: var(--green-light);
  margin: 2px 6px 2px 0;
}
.ach-badge svg { color: var(--green-dark); }
.btn svg { vertical-align: -3px; margin-right: 5px; }
.fab svg { display: block; }
.task-desc svg { vertical-align: -2px; }

/* ── Оверлей загрузки ───────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay-box {
  background: #fff;
  border-radius: 16px;
  padding: 22px 26px;
  text-align: center;
  max-width: 280px;
}
.overlay-box p { margin: 12px 0 0; font-size: 14px; }
.spinner {
  width: 34px; height: 34px;
  margin: 0 auto;
  border: 3px solid var(--green-light);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Модальные окна ─────────────────────────── */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* ── Тост ───────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 110;
  background: #2B2B2E;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 34px 16px;
  font-size: 14px;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 10px; }
