:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #18212b;
  --line: #243040;
  --text: #e8eef5;
  --muted: #8a9bb0;
  --accent: #3ddc97;
  --warn: #ffb547;
  --bad: #ff5d5d;
  --cold: #5eb0ff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(11, 15, 20, 0.92); backdrop-filter: blur(6px); z-index: 2;
}
.brand { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 18px; letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.conn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 14px; max-width: 60vw;
}
.conn span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.conn--ok .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 1.6s infinite; }
.conn--wait .dot { background: var(--warn); }
.conn--bad .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.45; } }
.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4;
  background: rgba(255, 181, 71, 0.1); border: 1px solid rgba(255, 181, 71, 0.35); color: #ffd9a0;
}
.grid {
  display: grid; gap: 12px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.tile {
  position: relative; background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px 16px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; min-height: 118px;
  transition: opacity 0.3s;
}
.tile.is-missing { opacity: 0.35; }
.tile.is-stale .value { color: var(--muted); }
.tile .label { width: 100%; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.tile .value { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; }
.tile .unit { color: var(--muted); font-size: 16px; }
.tile .note { width: 100%; color: var(--warn); font-size: 12px; }
.tile.is-warn .value { color: var(--warn); }
.tile.is-bad .value { color: var(--bad); }
.tile.is-cold .value { color: var(--cold); }
.bar { width: 100%; height: 8px; border-radius: 4px; background: #0e141b; margin-top: 8px; overflow: hidden; position: relative; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.25s linear; }
.bar--center::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--muted); }
.bar--center i { position: absolute; left: 50%; }
.tile--gauge {
  grid-column: span 2; min-height: 230px; flex-direction: column; align-items: center; justify-content: flex-end;
  flex-wrap: nowrap; padding-top: 6px;
}
.tile--gauge .label { text-align: center; width: auto; order: 3; }
.gauge { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: min(260px, 92%); }
.gauge-track, .gauge-fill { fill: none; stroke-width: 14; stroke-linecap: round; }
.gauge-track { stroke: #0e141b; }
.gauge-fill { stroke: var(--accent); stroke-dasharray: 0 100; opacity: 0; transition: stroke-dasharray 0.25s linear, stroke 0.3s; }
.gauge-center { display: flex; flex-direction: column; align-items: center; z-index: 1; margin-bottom: 4px; }
.tile--gauge .value { font-size: 58px; }
.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; padding: 4px 18px 18px;
}
@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
  .tile .value { font-size: 34px; }
  .tile--gauge .value { font-size: 44px; }
  .tile--gauge { min-height: 190px; }
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(6, 1fr); }
}

/* Telegram Mini App: компактнее, без «липкой» шапки (у Telegram своя) */
.in-telegram .topbar { position: static; padding: 10px 14px; }
.in-telegram .brand-sub { display: none; }
.in-telegram .grid { padding: 10px; gap: 8px; }
@media (max-width: 420px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
  .tile { min-height: 96px; padding: 10px 12px 12px; }
  .tile .label { font-size: 11px; }
  .tile .value { font-size: 32px; }
  .tile--gauge { min-height: 180px; }
  .tile--gauge .value { font-size: 42px; }
  .conn { font-size: 12px; padding: 6px 10px; max-width: 55vw; }
}

/* Переход к AI-разбору и «Мои авто» */
.ai-nav { display: flex; gap: 8px; margin: 12px 16px 0; }
.ai-nav a {
  flex: 1; text-align: center; text-decoration: none; color: var(--text); font-size: 14px; font-weight: 600;
  padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.ai-nav a:active { background: var(--panel-2); }
