:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0b0e13);
  --card: var(--tg-theme-secondary-bg-color, #151a22);
  --card-soft: rgba(255, 255, 255, 0.04);
  --text: var(--tg-theme-text-color, #eef2f7);
  --muted: var(--tg-theme-hint-color, #8d97a8);
  --line: rgba(255, 255, 255, 0.08);
  --on: #34d399;
  --off: #fb7185;
  --accent: #fbbf24;
  --radius: 20px;
  --shadow: 0 18px 40px -28px rgba(0, 0, 0, 0.9);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: var(--tg-theme-bg-color, #f4f6fa);
    --card: var(--tg-theme-secondary-bg-color, #ffffff);
    --card-soft: rgba(15, 23, 42, 0.04);
    --text: var(--tg-theme-text-color, #10151d);
    --muted: var(--tg-theme-hint-color, #6b7686);
    --line: rgba(15, 23, 42, 0.09);
    --shadow: 0 18px 40px -30px rgba(15, 23, 42, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-size: 15px;
  line-height: 1.45;
}

.page {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #1c1405;
  background: linear-gradient(150deg, #fde68a, #f59e0b);
  box-shadow: 0 10px 24px -14px rgba(245, 158, 11, 0.9);
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.is-loading svg { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Дати ---------- */

.dates {
  display: flex;
  gap: 8px;
  padding: 4px;
  border-radius: 16px;
  background: var(--card-soft);
  border: 1px solid var(--line);
}

.date-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.date-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.date-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Статус ---------- */

.status {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: start;
}

.status::before {
  content: "";
  position: absolute;
  inset: -40% -10% auto 20%;
  height: 180px;
  background: radial-gradient(60% 100% at 50% 0%, rgba(148, 163, 184, 0.35), transparent 70%);
  opacity: 0.5;
  pointer-events: none;
  transition: background 0.3s ease;
}

.status[data-state="on"]::before {
  background: radial-gradient(60% 100% at 50% 0%, rgba(52, 211, 153, 0.45), transparent 70%);
}

.status[data-state="off"]::before {
  background: radial-gradient(60% 100% at 50% 0%, rgba(251, 113, 133, 0.45), transparent 70%);
}

.status[data-state="plan"]::before {
  background: radial-gradient(60% 100% at 50% 0%, rgba(251, 191, 36, 0.4), transparent 70%);
}

.status-icon {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--card-soft);
  border: 1px solid var(--line);
}

.status[data-state="on"] .status-icon { color: var(--on); background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.3); }
.status[data-state="off"] .status-icon { color: var(--off); background: rgba(251, 113, 133, 0.14); border-color: rgba(251, 113, 133, 0.3); }
.status[data-state="plan"] .status-icon { color: var(--accent); background: rgba(251, 191, 36, 0.14); border-color: rgba(251, 191, 36, 0.3); }

.status-icon svg { width: 24px; height: 24px; }

.status-text { position: relative; min-width: 0; }

.status-text h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.status-text p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.status-meta {
  position: relative;
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.chip {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Банер (застарілі дані / офлайн) ---------- */

.banner {
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.45;
}

.countdown {
  margin-top: 6px !important;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

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

.card {
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- Групи ---------- */

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

.card-note {
  margin: -4px 0 12px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.ghost-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.ghost-btn {
  padding: 7px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, color 0.18s ease;
}

.ghost-btn:active { transform: scale(0.96); }
.ghost-btn:hover { color: var(--text); }

.group-btn {
  padding: 10px 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.group-btn:active { transform: scale(0.95); }

.group-btn[aria-pressed="true"] {
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.55);
  color: var(--text);
}

/* ---------- Таймлайн ---------- */

.timeline {
  position: relative;
  height: 46px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card-soft);
  border: 1px solid var(--line);
}

.timeline-track {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 211, 153, 0.34), rgba(52, 211, 153, 0.2));
  background-size: 12.5% 100%, 100% 100%;
  background-position: 0 0, 0 0;
}

.seg {
  position: absolute;
  top: 0;
  bottom: 0;
  background-image: repeating-linear-gradient(
    135deg,
    rgba(251, 113, 133, 0.95) 0 5px,
    rgba(225, 29, 72, 0.85) 5px 10px
  );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.timeline-track-common {
  background-image:
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    repeating-linear-gradient(
      135deg,
      rgba(251, 113, 133, 0.42) 0 5px,
      rgba(225, 29, 72, 0.32) 5px 10px
    );
  background-size: 12.5% 100%, 100% 100%;
}

.seg-light {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.95), rgba(16, 185, 129, 0.82));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.timeline-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.timeline-now::after {
  content: "";
  position: absolute;
  top: -1px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: var(--text);
}

.timeline-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 1px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-on { background: var(--on); }
.dot-off { background: var(--off); }
.dot-now { background: var(--text); }

/* ---------- Підсумки ---------- */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat strong {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-off strong { color: var(--off); }
.stat-on strong { color: var(--on); }

/* ---------- Списки ---------- */

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.rows li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.rows li:first-child { border-top: 0; padding-top: 2px; }
.rows li:last-child { padding-bottom: 2px; }

.rows .range {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.rows .dur {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
}

.rows .empty {
  display: block;
  padding: 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.dot-red { background: var(--off); }
.dot-green { background: var(--on); }

.footnote {
  margin: 2px 4px 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

.footnote.is-error { color: var(--off); }

/* ---------- Тиждень ---------- */

.week {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.week-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 10px;
}

.week-day {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.week-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--card-soft);
  overflow: hidden;
}

.week-track.is-empty {
  background: repeating-linear-gradient(
    90deg,
    var(--line) 0 4px,
    transparent 4px 8px
  );
}

.week-bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(251, 113, 133, 0.9), rgba(225, 29, 72, 0.8));
}

.week-bar.is-today {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.95), rgba(245, 158, 11, 0.85));
}

.week-value {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}

/* ---------- Налаштування сповіщень ---------- */

.settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.setting-row:first-child {
  padding-top: 0;
  border-top: 0;
}

.setting-label {
  font-size: 13px;
  font-weight: 600;
}

.setting-control {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.switch {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.switch:active { transform: scale(0.96); }

.switch[aria-checked="true"] {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.5);
  color: var(--text);
}

.pill {
  padding: 6px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease;
}

.pill:active { transform: scale(0.95); }

.time-input {
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  color-scheme: dark;
}

.time-dash {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.pill[aria-pressed="true"] {
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.55);
  color: var(--text);
}

@media (max-width: 360px) {
  .groups { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .status { padding: 16px; }
  .status-text h2 { font-size: 19px; }
}
