/* Приложение «Уровень воды у дачи» — мобильная вёрстка, тёмная тема. */

:root {
  --bg: #0b1220;
  --bg-soft: #111c2f;
  --card: #14203a;
  --card-2: #1a2949;
  --line: #26375c;
  --text: #eaf1ff;
  --muted: #9db0d0;
  --ok: #35d07f;
  --warn: #ffc247;
  --danger: #ff5d5d;
  --accent: #57b6ff;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 12px calc(24px + var(--safe-bottom));
}

/* ------------------------------------------------------------- шапка */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 4px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(11, 18, 32, 0));
  backdrop-filter: blur(6px);
}

.topbar__main { flex: 1; min-width: 0; }
.topbar__place { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__meta { color: var(--muted); font-size: 12px; }

.iconbtn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 18px;
}
.iconbtn svg { width: 22px; height: 22px; fill: currentColor; }
.iconbtn:active { background: var(--card-2); }
.iconbtn.is-busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- баннер */

.banner {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 194, 71, .12);
  border: 1px solid rgba(255, 194, 71, .4);
  color: #ffe0a3;
  font-size: 13px;
}
.banner--error { background: rgba(255, 93, 93, .12); border-color: rgba(255, 93, 93, .45); color: #ffc9c9; }

/* ------------------------------------------------------------- карточки */

.content { display: grid; gap: 14px; }

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

.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card__head h2 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.sub { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }

.tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

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

.status { border-left: 5px solid var(--line); }
.status--ok { border-left-color: var(--ok); }
.status--warning { border-left-color: var(--warn); }
.status--danger { border-left-color: var(--danger); }
.status--unknown { border-left-color: var(--muted); }

.status__head { display: flex; gap: 12px; align-items: flex-start; }
.status__title { font-size: 21px; font-weight: 700; line-height: 1.2; }
.status__sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

.dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted); }
.status--ok .dot { background: var(--ok); box-shadow: 0 0 0 6px rgba(53, 208, 127, .15); }
.status--warning .dot { background: var(--warn); box-shadow: 0 0 0 6px rgba(255, 194, 71, .15); }
.status--danger .dot { background: var(--danger); box-shadow: 0 0 0 6px rgba(255, 93, 93, .18); }

.status__facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0 0;
}
.status__facts dt { color: var(--muted); font-size: 12px; }
.status__facts dd { margin: 2px 0 0; font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- линейка уровня */

.gauge { display: flex; gap: 12px; align-items: stretch; }
.gauge__scale {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 54px;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 2px 0;
}
.gauge__num--now { color: var(--text); }

.gauge__bar {
  position: relative;
  flex: 1;
  height: 210px;
  border-radius: 12px;
  background: linear-gradient(180deg, #1d2c4d, #16233d);
  border: 1px solid var(--line);
  overflow: hidden;
}
.gauge__zone { position: absolute; left: 0; right: 0; }
.gauge__zone--warn { background: rgba(255, 194, 71, .22); }
.gauge__zone--danger { background: rgba(255, 93, 93, .26); }

.gauge__line { position: absolute; left: 0; right: 0; height: 2px; background: var(--warn); }
.gauge__line--warn { background: var(--warn); }
.gauge__line span {
  position: absolute; right: 6px; top: -8px;
  font-size: 10px; color: #ffe6b0; background: rgba(11, 18, 32, .75);
  padding: 1px 5px; border-radius: 6px;
}
.gauge__line--warn { background: var(--warn); }
.gauge__line:not(.gauge__line--warn) { background: var(--danger); }
.gauge__line:not(.gauge__line--warn) span { color: #ffc9c9; }

.gauge__marker {
  position: absolute; left: 0; right: 0;
  height: 3px; background: var(--accent);
  box-shadow: 0 0 12px rgba(87, 182, 255, .8);
  transition: bottom .4s ease;
}
.gauge__marker b {
  position: absolute; right: 6px; bottom: 4px;
  font-size: 12px; background: var(--accent); color: #04223a;
  padding: 2px 7px; border-radius: 8px; font-variant-numeric: tabular-nums;
}

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.swatch--danger { background: var(--danger); }
.swatch--warn { background: var(--warn); }
.swatch--ok { background: var(--ok); }

.stations { display: grid; gap: 8px; margin-top: 12px; }
.station-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 9px 11px; background: var(--card-2); border-radius: 12px; font-size: 13px;
}
.station-row small { color: var(--muted); }
.station-row b { font-variant-numeric: tabular-nums; }
.station-row em { font-style: normal; color: var(--accent); font-size: 11.5px; }
.station-row--primary { border: 1px solid rgba(87, 182, 255, .45); background: rgba(87, 182, 255, .08); }

/* ------------------------------------------------------------- ветер */

.wind { display: flex; gap: 14px; align-items: center; }
.compass { position: relative; width: 150px; flex: none; }
.compass__svg { width: 150px; height: 150px; display: block; }
.compass__ring { fill: rgba(255, 255, 255, .03); stroke: var(--line); stroke-width: 1.5; }
.compass__ticks line { stroke: var(--line); stroke-width: 1.5; }
.compass__ticks text { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.compass__arrow path { fill: var(--accent); }
.compass__arrow { transition: transform .5s ease; transform-origin: 100px 100px; }
.compass__hub { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
/* подпись выносим ПОД круг, чтобы «Ю» не наезжало на окружность */
.compass__label { margin-top: 8px; text-align: center; font-size: 12px; line-height: 1.25; color: var(--muted); }
.compass__label b { display: block; color: var(--text); font-size: 15px; }

.wind__numbers { flex: 1; min-width: 0; }
.big, .gust { display: flex; align-items: baseline; gap: 6px; }
.big b, .gust b { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.gust b { font-size: 24px; color: var(--warn); }
.big span, .gust span { color: var(--muted); font-size: 13px; }
.big small, .gust small { display: block; width: 100%; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.gust { margin-top: 10px; }
.big em, .gust em { font-style: normal; color: var(--text); font-variant-numeric: tabular-nums; }

.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin: 12px 0 0; }
.mini dt { color: var(--muted); font-size: 11.5px; }
.mini dd { margin: 0; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mini--wide { grid-template-columns: 1fr; gap: 8px; margin-top: 0; }
.mini--wide > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  background: var(--card-2); border-radius: 12px; padding: 9px 12px;
}
.mini--wide dd { font-size: 14px; text-align: right; }

.chart { width: 100%; display: block; touch-action: pan-y; }
.chart--tall { height: 220px; }

/* ------------------------------------------------------------- риск */

.toggle { display: flex; gap: 4px; background: var(--card-2); padding: 3px; border-radius: 12px; }
.toggle__btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 12px; padding: 7px 10px; border-radius: 9px; font-weight: 600;
}
.toggle__btn.is-active { background: var(--accent); color: #04223a; }

.risk { display: grid; gap: 8px; margin-bottom: 12px; }
.risk__item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  background: var(--card-2); border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.risk__item span { color: var(--muted); }
.risk__item b { font-size: 17px; font-variant-numeric: tabular-nums; }
.risk__item b.level-danger { color: var(--danger); }
.risk__item b.level-warning { color: var(--warn); }
.risk__item b.level-ok { color: var(--ok); }

/* ------------------------------------------------------------- море и источники */

.sea { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sea div { background: var(--card-2); border-radius: 12px; padding: 10px; }
.sea span { display: block; color: var(--muted); font-size: 11.5px; }
.sea b { font-size: 17px; font-variant-numeric: tabular-nums; }

.sources { margin-top: 14px; }
.sources summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.sources ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.sources li { margin-bottom: 4px; }

/* ------------------------------------------------------------- подвал */

.footer {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 18px; padding: 0 4px; color: var(--muted); font-size: 11.5px;
}
.footer__warn { color: #c8a86a; }

/* ------------------------------------------------------------- настройки */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(4, 8, 16, .7); }
.sheet__panel {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--bg-soft);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line);
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheet__head h2 { margin: 0; font-size: 17px; }
.sheet__body { overflow-y: auto; padding: 4px 16px 8px; display: grid; gap: 12px; }
.sheet__foot {
  display: flex; gap: 10px; padding: 12px 16px calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}

.field { display: grid; gap: 5px; font-size: 13px; }
.field > span { color: var(--muted); }
.field input {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 15px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.calib { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.calib__row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }

.btn {
  border: 0; border-radius: 14px; padding: 13px 16px; font-size: 15px; font-weight: 650;
  background: var(--accent); color: #04223a;
}
.btn--ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn:active { transform: scale(.99); }
.sheet__foot .btn { flex: 1; }

.more summary { color: var(--muted); font-size: 13px; cursor: pointer; margin-bottom: 8px; }
.more[open] { display: grid; gap: 12px; }

.stationlist { display: grid; gap: 6px; max-height: 190px; overflow-y: auto; }
.stationlist button {
  text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 9px 11px; font-size: 13px;
}
.stationlist button.is-active { border-color: var(--accent); background: rgba(87, 182, 255, .12); }
.stationlist small { display: block; color: var(--muted); font-size: 11.5px; }

@media (max-width: 380px) {
  .gauge__bar { height: 180px; }
  .compass, .compass__svg { width: 124px; }
  .compass__svg { height: 124px; }
  .wind { gap: 10px; }
}
