:root {
  /* Palette sampled from the client's own tracker sheet (Google Sheets "Звички" tab):
     black canvas, white type, #3C78D8 accent blue, mid-gray cards. Fixed brand look —
     intentionally not overridden by the viewer's Telegram theme (see app.js). */
  --tg-bg: #000000;
  --tg-text: #ffffff;
  --tg-hint: #9aa0a6;
  --tg-link: #3c78d8;
  --tg-button: #3c78d8;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #1c1c1e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}

.app__header {
  padding: 8px 4px 16px;
}

.app__title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
}

.app__date {
  margin: 0;
  color: var(--tg-hint);
  font-size: 14px;
}

.stats {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  flex: 1;
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-card__value {
  font-size: 26px;
  font-weight: 700;
  color: var(--tg-button);
  transition: color 0.3s ease;
}

.stat-card__label {
  font-size: 13px;
  color: var(--tg-hint);
}

.stat-card__trophy {
  display: none;
  font-size: 20px;
  line-height: 1;
  margin-top: 2px;
}

.stat-card--complete .stat-card__trophy {
  display: block;
  animation: trophy-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-card--complete {
  animation: card-glow 0.6s ease;
}

@keyframes trophy-pop {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  60% { transform: scale(1.25) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes card-glow {
  0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
  40% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

.habit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tg-secondary-bg);
  border-radius: 12px;
  padding: 14px 14px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.habit-row:active {
  background: color-mix(in srgb, var(--tg-secondary-bg) 80%, var(--tg-button) 20%);
}

.habit-row__check {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 8px;
  border: 2px solid var(--tg-hint);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.habit-row__check svg {
  width: 16px;
  height: 16px;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.habit-row--done .habit-row__check {
  background: var(--tg-button);
  border-color: var(--tg-button);
}

.habit-row--done .habit-row__check svg {
  opacity: 1;
}

.habit-row__name {
  font-size: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-row--done .habit-row__name {
  color: var(--tg-hint);
  text-decoration: line-through;
}

.habit-row__edit-input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-family: inherit;
  color: var(--tg-text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--tg-button);
  padding: 0 0 2px;
}

.habit-row__edit-input:focus {
  outline: none;
}

.habit-row__icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--tg-hint);
  font-size: 15px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.habit-row__icon-btn:active {
  background: color-mix(in srgb, var(--tg-secondary-bg) 60%, var(--tg-hint) 20%);
}

.add-habit {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-habit__input {
  flex: 1;
  min-width: 0;
  background: var(--tg-secondary-bg);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--tg-text);
  font-size: 15px;
  font-family: inherit;
}

.add-habit__input:focus {
  outline: none;
  border-color: var(--tg-button);
}

.add-habit__input::placeholder {
  color: var(--tg-hint);
}

.add-habit__btn {
  flex: none;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.add-habit__btn:active {
  opacity: 0.85;
}

.error-banner {
  background: color-mix(in srgb, var(--tg-secondary-bg) 70%, #ff4d4f 30%);
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 12px;
}

.demo-banner {
  background: color-mix(in srgb, var(--tg-secondary-bg) 55%, var(--tg-button) 45%);
  color: #fff;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  margin: 0 0 12px;
  text-align: center;
}

/* ---- bottom tab bar (4-screen menu) ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--tg-bg) 85%, #ffffff 4%);
  border-top: 1px solid color-mix(in srgb, var(--tg-bg) 60%, var(--tg-hint) 25%);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  backdrop-filter: blur(8px);
}

.tabbar__btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--tg-hint);
  padding: 8px 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease;
}

.tabbar__btn--active {
  color: var(--tg-button);
}

.tabbar__icon {
  width: 24px;
  height: 24px;
}

.tabbar__label {
  font-size: 11px;
  font-weight: 600;
}

/* ---- screen container ---- */
.view {
  animation: view-in 0.18s ease;
}

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

/* ---- placeholder screens (Home/Dashboard/Insights, filled in next steps) ---- */
.placeholder {
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 28px 20px;
  text-align: center;
  color: var(--tg-hint);
  margin-top: 8px;
}

.placeholder__title {
  color: var(--tg-text);
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 8px;
}

.placeholder__text {
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
}

/* ---- habits empty state ---- */
.empty-state {
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 24px 20px;
  text-align: center;
  margin-bottom: 12px;
}

.empty-state__text {
  color: var(--tg-hint);
  font-size: 14px;
  line-height: 1.45;
  margin: 0 0 16px;
}

/* ---- "choose from list" button ---- */
.picker-open {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: var(--tg-button);
  border: 1px dashed color-mix(in srgb, var(--tg-button) 55%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.picker-open:active {
  background: color-mix(in srgb, var(--tg-button) 12%, transparent);
}

/* ---- picker sheet (onboarding + add from list) ---- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  animation: fade-in 0.18s ease;
}

.sheet__panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  background: var(--tg-bg);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid color-mix(in srgb, var(--tg-bg) 55%, var(--tg-hint) 30%);
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  animation: sheet-up 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
}

.sheet__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.sheet__close {
  border: none;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}

.sheet__body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.picker-group {
  margin-bottom: 16px;
}

.picker-group__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 0 0 10px;
}

.picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid color-mix(in srgb, var(--tg-hint) 45%, transparent);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.chip--selected {
  background: var(--tg-button);
  border-color: var(--tg-button);
  color: var(--tg-button-text);
}

.chip--added {
  opacity: 0.45;
  pointer-events: none;
}

.sheet__custom {
  display: flex;
  gap: 8px;
  margin: 4px 0 12px;
}

.picker-confirm {
  width: 100%;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.picker-confirm:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---- home screen ---- */
.card {
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.card__title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--tg-text);
}

.home-gauge {
  display: flex;
  align-items: center;
  gap: 18px;
}

.gauge-wrap {
  position: relative;
  width: 108px;
  height: 108px;
  flex: none;
}

.gauge-ring {
  width: 108px;
  height: 108px;
  transform: rotate(-90deg);
}

.gauge-ring__bg {
  fill: none;
  stroke: color-mix(in srgb, var(--tg-bg) 40%, var(--tg-hint) 25%);
  stroke-width: 10;
}

.gauge-ring__fg {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gauge-center__pct {
  font-size: 24px;
  font-weight: 700;
}

.home-gauge__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.home-gauge__label {
  font-size: 14px;
  color: var(--tg-hint);
}

.home-gauge__count {
  font-size: 22px;
  font-weight: 700;
}

.notify .kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.notify .kv-row + .kv-row {
  border-top: 1px solid color-mix(in srgb, var(--tg-bg) 55%, var(--tg-hint) 18%);
}

.kv-key {
  font-size: 14px;
  color: var(--tg-hint);
}

.kv-val {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.kv-val--ok { color: #2ecc71; }
.kv-val--no { color: #ff7a45; }

.habit-table {
  padding: 8px 12px;
}

.ht-row {
  display: grid;
  grid-template-columns: 1fr 44px 60px 64px;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
}

.ht-row + .ht-row {
  border-top: 1px solid color-mix(in srgb, var(--tg-bg) 55%, var(--tg-hint) 15%);
}

.ht-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--tg-hint);
  font-weight: 700;
}

.ht-head span:not(:first-child),
.ht-mtd,
.ht-mom {
  text-align: right;
}

.ht-name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ht-mtd {
  font-size: 14px;
  font-weight: 600;
}

.ht-mom {
  font-size: 13px;
  font-weight: 600;
}

.ht-mom--up { color: #2ecc71; }
.ht-mom--down { color: #ff7a45; }
.ht-mom--flat { color: var(--tg-hint); }

.ht-spark {
  display: flex;
  justify-content: flex-end;
}

.ht-head .ht-spark,
.ht-row span:last-child {
  text-align: right;
}

.chart-box {
  position: relative;
  height: 180px;
}

/* ---- dashboard ---- */
.segmented {
  display: flex;
  background: var(--tg-secondary-bg);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}

.segmented__btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--tg-hint);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 0;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented__btn--active {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

/* ---- insights ---- */
.duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.mini-card {
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 3px solid var(--tg-hint);
}

.mini-card--ok { border-left-color: #2ecc71; }
.mini-card--no { border-left-color: #ff7a45; }

.mini-card__label {
  font-size: 12px;
  color: var(--tg-hint);
}

.mini-card__name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-card__pct {
  font-size: 20px;
  font-weight: 700;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.pill {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tg-bg) 50%, var(--tg-hint) 20%);
}

.pill--ok { background: rgba(46, 204, 113, 0.18); color: #2ecc71; }
.pill--no { background: rgba(255, 122, 69, 0.18); color: #ff7a45; }
.pill--flat { color: var(--tg-hint); }

.trend-list {
  margin-top: 12px;
}

.trend-row {
  display: grid;
  grid-template-columns: 1fr auto 60px;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
}

.trend-row + .trend-row {
  border-top: 1px solid color-mix(in srgb, var(--tg-bg) 55%, var(--tg-hint) 15%);
}

.trend-row__name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trend-row__range {
  font-size: 12px;
  color: var(--tg-hint);
  white-space: nowrap;
}

.corr-grid {
  display: grid;
  gap: 2px;
  margin: 4px 0 12px;
}

.corr-head {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--tg-hint);
  min-height: 18px;
}

.corr-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 9px;
  color: #fff;
}

.corr-legend {
  margin: 0 0 12px;
  padding-left: 22px;
  color: var(--tg-hint);
  font-size: 12px;
  line-height: 1.5;
}

.corr-summary {
  font-size: 13px;
  line-height: 1.6;
}

.corr-summary__key {
  color: var(--tg-hint);
}

/* ---- day bar + calendar ---- */
.daybar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.daybar__date {
  flex: 1;
  background: var(--tg-secondary-bg);
  border: none;
  color: var(--tg-text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.daybar__arrow {
  background: var(--tg-secondary-bg);
  border: none;
  color: var(--tg-text);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 20px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}

.daybar__arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.daybar__today {
  width: 100%;
  background: none;
  border: 1px solid #444746;
  color: var(--tg-hint);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.35;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.habit-row--locked .habit-row__check,
.habit-row--locked .habit-row__name {
  cursor: default;
}

.cal__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 12px;
}

.cal__month {
  font-size: 16px;
  font-weight: 700;
}

.cal__arrow {
  background: var(--tg-secondary-bg);
  border: none;
  color: var(--tg-text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 20px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}

.cal__arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal__weekday {
  text-align: center;
  font-size: 12px;
  color: var(--tg-hint);
  padding-bottom: 2px;
}

.cal__day {
  aspect-ratio: 1 / 1;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #1c1c1e;
  color: var(--tg-text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.cal__day--blank {
  background: none;
  cursor: default;
}

.cal__day--future {
  opacity: 0.25;
  cursor: default;
}

.cal__day--l1 { background: color-mix(in srgb, var(--tg-link) 28%, #1c1c1e); }
.cal__day--l2 { background: color-mix(in srgb, var(--tg-link) 58%, #1c1c1e); }
.cal__day--l3 { background: var(--tg-link); font-weight: 700; }

.cal__day--today { border-color: var(--tg-text); }

.cal__day--selected {
  outline: 2px solid var(--tg-text);
  outline-offset: -1px;
}

.cal__legend {
  margin: 14px 0 12px;
  font-size: 12px;
  color: var(--tg-hint);
}
