:root {
  --ink: #07110b;
  --text: #07110b;
  --text-soft: #1a2a1f;
  --hint: #3a4d40;
  --mint: #5fb82e;
  --mint-deep: #3f8f18;
  --danger: #b83228;
  --line: rgba(7, 17, 11, 0.14);
  --card: rgba(255, 255, 255, 0.86);
  --shadow: 0 14px 30px rgba(7, 17, 11, 0.12);
  --radius: 16px;
  --tg-btn: var(--tg-theme-button-color, var(--mint-deep));
  --tg-btn-text: var(--tg-theme-button-text-color, #fff);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Manrope", system-ui, sans-serif;
  font-weight: 600;
  color: var(--text);
  background: #eef3ea;
  -webkit-font-smoothing: antialiased;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1000px 520px at 8% -8%, rgba(95, 184, 46, 0.32), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(30, 70, 45, 0.16), transparent 50%),
    linear-gradient(165deg, #f8fcf4 0%, #e7f1df 50%, #d8e8ce 100%);
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--tabbar-h) + 18px + var(--safe-bottom));
}

.top { margin-bottom: 14px; animation: rise 0.4s ease both; }
.brand {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: clamp(1.7rem, 7vw, 2.2rem);
  letter-spacing: -0.04em;
  color: #031008;
  line-height: 0.95;
}
.sub {
  margin: 6px 0 0;
  font-weight: 700;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.view { animation: rise 0.35s ease both; }
.section-title {
  margin: 18px 0 8px;
  font-family: "Syne", sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  color: #031008;
}
.section-title:first-child { margin-top: 0; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); }
.dot.warn { background: #d4a017; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-weight: 800;
  font-size: 0.84rem;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  color: var(--ink);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  box-shadow: 0 8px 18px rgba(63, 143, 24, 0.28);
}
.btn.ghost {
  background: rgba(255,255,255,0.78);
  border: 1px solid var(--line);
}
.btn.danger {
  background: rgba(184, 50, 40, 0.12);
  color: var(--danger);
}
.btn.compact { padding: 8px 10px; font-size: 0.78rem; }
.btn.block { width: 100%; }

.row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 4px;
}

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.card-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.card-mini .name {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 0.98rem;
  color: #031008;
}
.card-mini .meta-line {
  margin: 2px 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--hint);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.card-name {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 1.12rem;
  color: #031008;
}
.badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(95, 184, 46, 0.2);
  color: #246012;
}
.badge.off { background: rgba(7,17,11,0.1); color: var(--hint); }
.badge.ok { background: rgba(95, 184, 46, 0.22); color: #1f5c10; }
.badge.blocked { background: rgba(184, 50, 40, 0.16); color: #8a241c; }
.badge.error { background: rgba(196, 120, 20, 0.18); color: #8a4b00; }
.badge.unknown { background: rgba(7,17,11,0.1); color: var(--hint); }
.badge.paused { background: rgba(7,17,11,0.1); color: var(--hint); }
.health-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.card-stats {
  margin-top: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  line-height: 1.4;
}
.tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.tag.yes { background: rgba(95,184,46,0.16); color: #1f5c10; }
.tag.no { background: rgba(184,50,40,0.12); color: #8a241c; }
.card-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.card-actions .btn { padding: 9px 8px; font-size: 0.78rem; }

.alert-item {
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.alert-item a {
  color: #1f5c10;
  font-weight: 800;
  text-decoration: none;
}
.alert-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--hint);
  margin-bottom: 4px;
}
.alert-title {
  margin: 0;
  font-weight: 800;
  color: #031008;
  font-size: 0.95rem;
  line-height: 1.3;
}
.alert-price {
  margin: 4px 0 0;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  color: #246012;
}
.alert-loc {
  margin: 4px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--hint);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-tile {
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.stat-tile .label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-tile .value {
  margin: 6px 0 0;
  font-family: "Syne", sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: #031008;
  letter-spacing: -0.02em;
}
.stat-tile.wide { grid-column: 1 / -1; }

.settings {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.interval-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 800;
  font-size: 0.88rem;
}
.interval-controls { display: flex; align-items: center; gap: 8px; }
.interval-controls input {
  width: 100px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
}
.hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--hint);
  line-height: 1.4;
}
.empty {
  padding: 16px 4px;
  color: var(--text-soft);
  font-weight: 700;
  line-height: 1.4;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(247, 251, 242, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 800;
  font-size: 0.72rem;
  color: var(--hint);
  padding: 10px 4px;
  border-radius: 12px;
  cursor: pointer;
}
.tab.active {
  color: #031008;
  background: rgba(95, 184, 46, 0.18);
}

.sheet[hidden] { display: none; }
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  align-items: end;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 17, 11, 0.4);
}
.sheet-panel {
  position: relative;
  max-height: min(92vh, 740px);
  overflow: auto;
  background: #f7fbf2;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -12px 40px rgba(7, 17, 11, 0.2);
  animation: slide 0.25s ease both;
}
.sheet-panel h2 {
  margin: 0 0 14px;
  font-family: "Syne", sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 11px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-soft);
}
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
}
.field input:focus {
  outline: 2px solid rgba(95, 184, 46, 0.5);
  border-color: transparent;
}
.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 12px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(90vw, 420px);
  padding: 12px 14px;
  border-radius: 14px;
  background: #07110b;
  color: #f4f7f1;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

.boot-error {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef3ea;
  text-align: center;
  font-weight: 700;
  color: var(--ink);
}
.boot-error[hidden] { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slide {
  from { transform: translateY(20px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}
