:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #707579);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --section-header: var(--tg-theme-section-header-text-color, var(--hint));
  --destructive: var(--tg-theme-destructive-text-color, #ff3b30);
  --warn: #ff9500;
  --success: #34c759;
  --bottom-nav-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
}

#app-header {
  padding: 12px 16px 8px;
}
#header-title { font-size: 18px; font-weight: 600; }
#header-sub { font-size: 12px; margin-top: 2px; }

.muted { color: var(--hint); font-size: 12px; }

#screen { padding: 0 12px; }

/* ─── Cards / Rows ────────────────────────────── */
.card {
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
}
.card h3 { margin: 0 0 10px 0; font-size: 14px; font-weight: 600; }
.card .h-extra { float: right; font-size: 12px; color: var(--hint); font-weight: normal; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
  gap: 8px;
}
.row:last-child { border: none; padding-bottom: 0; }
.row:first-child { padding-top: 0; }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value { font-weight: 600; flex-shrink: 0; }
.row.me { color: var(--button); }

/* ─── Inputs / Buttons ────────────────────────── */
input[type="text"], input[type="date"], input[type="number"], input[type="url"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(128,128,128,0.25);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--button); }

label { display: block; margin-bottom: 6px; color: var(--hint); font-size: 12px; }

button.primary {
  background: var(--button); color: var(--button-text);
  border: none; padding: 10px 16px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
  width: 100%;
}
button.primary:disabled { opacity: 0.6; }
button.secondary {
  background: var(--secondary-bg); color: var(--text);
  border: none; padding: 8px 14px; border-radius: 10px;
  font: inherit; cursor: pointer;
}

/* ─── Badges ──────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 8px;
  font-size: 11px; background: var(--button); color: var(--button-text);
}
.badge.warn { background: var(--warn); color: white; }
.badge.success { background: var(--success); color: white; }
.badge.quiet { background: var(--hint); color: white; }

/* ─── States ──────────────────────────────────── */
.loading, .empty { text-align: center; padding: 30px 0; color: var(--hint); }
.error { color: var(--destructive); padding: 10px; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--hint); border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Bottom navigation ───────────────────────── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  display: flex; justify-content: space-around;
  background: var(--bg);
  border-top: 1px solid rgba(128,128,128,0.15);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--hint);
  font-size: 18px;
  padding-top: 4px;
}
.nav-item span { font-size: 10px; margin-top: 2px; color: var(--hint); }
.nav-item.active { color: var(--button); }
.nav-item.active span { color: var(--button); }

/* ─── Прочее ──────────────────────────────────── */
.list-link {
  display: block; padding: 12px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
  color: var(--text); text-decoration: none;
}
.list-link:last-child { border: none; }
.list-link::after { content: '›'; float: right; color: var(--hint); }

.examples {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
}
.example {
  background: var(--secondary-bg);
  border: none; padding: 6px 10px; border-radius: 14px;
  font-size: 12px; cursor: pointer; color: var(--text);
}

.bar {
  height: 22px; border-radius: 4px;
  background: rgba(128,128,128,0.18);
  position: relative; overflow: hidden; margin-top: 4px;
}
.bar > .fill { height: 100%; background: var(--button); }
.bar > .label {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  color: var(--text); font-size: 11px; font-weight: 600;
  text-shadow: 0 0 2px var(--bg);
}

.hist-row {
  display: grid; grid-template-columns: 60px 1fr 70px;
  align-items: center; gap: 8px; padding: 4px 0;
  font-size: 12px;
}

.metric-help { font-size: 13px; line-height: 1.45; }
.metric-help h4 { margin: 0 0 8px 0; font-size: 13px; color: var(--text); }
.metric-help ul { margin: 0; padding-left: 18px; color: var(--text); }
.metric-help li { margin: 0 0 6px 0; word-break: break-word; }
.metric-help li:last-child { margin-bottom: 0; }
