/* Экран спроектирован в логических единицах панели 800×480.
   --u — один «пиксель панели»; вся типографика и отступы масштабируются от него. */
:root {
  --u: min(calc(100vw / 800), calc(100vh / 480));
  --bg: #b9c4cc;
  --panel: #c9d2d9;
  --navy: #13234a;
  --frame: #f2e9c4;
  --frame-border: #e0b84a;
  --red: #e8262a;
  --blue: #1564d8;
  --btn: #9eabb6;
  --btn-dark: #5f6d7a;
  --btn-light: #e3e8ec;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #1a1d21;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hmi {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 320px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) calc(var(--u) * 155);
  grid-template-rows:
    calc(var(--u) * 17) minmax(0, 1fr) calc(var(--u) * 46)
    calc(var(--u) * 76);
  grid-template-areas:
    "title clock"
    "trend side"
    "tools tools"
    "nav   nav";
  background: var(--bg);
  color: #111;
  user-select: none;
}

/* ---------- Заголовок и часы ---------- */
.title,
.clock {
  background: var(--navy);
  color: #fff;
  font-weight: bold;
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
}
.title {
  grid-area: title;
  justify-content: center;
  font-size: calc(var(--u) * 10);
  border-right: calc(var(--u) * 3) solid #6d7d92;
}
.clock {
  grid-area: clock;
  justify-content: center;
  font-size: calc(var(--u) * 10.5);
  letter-spacing: 0.02em;
}

/* ---------- Тренд ---------- */
.trend {
  grid-area: trend;
  margin: calc(var(--u) * 3) calc(var(--u) * 3) calc(var(--u) * 2)
    calc(var(--u) * 3);
  background: var(--frame);
  border: calc(var(--u) * 1.5) solid var(--frame-border);
  position: relative;
  min-height: 0;
}
.trend canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Правая панель ---------- */
.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 3);
  padding: calc(var(--u) * 3) calc(var(--u) * 2) calc(var(--u) * 2)
    calc(var(--u) * 3);
  min-height: 0;
}
.vgroup {
  background: var(--panel);
  border: 1px solid #8a98a4;
  box-shadow: inset 1px 1px 0 #eef2f5;
  padding: calc(var(--u) * 2) calc(var(--u) * 3);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  flex: 1 1 0;
  min-height: 0;
}
.vbox {
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 1.5);
}
.vlabel {
  font-size: calc(var(--u) * 7.6);
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vlabel.red {
  color: var(--red);
}
.vlabel.blue {
  color: var(--blue);
}
.vfield {
  font-size: calc(var(--u) * 17);
  font-weight: bold;
  text-align: center;
  line-height: 1.15;
  padding: calc(var(--u) * 1) 0;
  border: 1px solid #6f7f8c;
  box-shadow:
    inset 1px 1px 0 #7d8b96,
    inset -1px -1px 0 #fff;
  white-space: nowrap;
  overflow: hidden;
}
.vfield.red {
  color: var(--red);
}
.vfield.blue {
  color: var(--blue);
}
.vfield.moment {
  background: #dde6ec;
}
.vfield.graph.red {
  background: #f6cfd2;
}
.vfield.graph.blue {
  background: #d4e6f7;
}

.sbtns {
  background: var(--panel);
  border: 1px solid #8a98a4;
  padding: calc(var(--u) * 4) calc(var(--u) * 3);
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 6);
}
.sbtn {
  height: calc(var(--u) * 37);
  border: 1px solid #333;
  color: #fff;
  font-size: calc(var(--u) * 10);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.45),
    inset -1px -1px 0 rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sbtn.archive {
  background: linear-gradient(#77753f, #5c5b2c);
}
.sbtn.delete {
  background: linear-gradient(#d4552a, #b23e14);
}
.sbtn:active {
  filter: brightness(0.85);
}

/* ---------- Панель инструментов тренда ---------- */
.tools {
  grid-area: tools;
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 4);
  padding: calc(var(--u) * 3) calc(var(--u) * 2) calc(var(--u) * 3)
    calc(var(--u) * 3);
  border-top: 1px solid #8a98a4;
  border-bottom: 1px solid #8a98a4;
  min-width: 0;
}
.tgap {
  width: calc(var(--u) * 8);
  flex: 0 0 auto;
}
.tbtn {
  flex: 0 0 auto;
  width: calc(var(--u) * 49);
  height: calc(var(--u) * 37);
  background: var(--btn);
  border: 1px solid #404b55;
  box-shadow:
    inset 1px 1px 0 var(--btn-light),
    inset -1px -1px 0 var(--btn-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tbtn svg {
  width: 80%;
  height: 80%;
}
.tbtn:active,
.tbtn.pressed {
  box-shadow:
    inset 1px 1px 0 var(--btn-dark),
    inset -1px -1px 0 var(--btn-light);
  filter: brightness(0.9);
}
.tbtn.arrow {
  font-size: calc(var(--u) * 22);
  font-weight: bold;
  letter-spacing: -0.08em;
}
.tbtn.arrow.blue {
  color: #1d4fe0;
  width: calc(var(--u) * 52);
}
.tbtn.arrow.green {
  color: #2cf03a;
  width: calc(var(--u) * 62);
  background: #6e7c88;
  box-shadow:
    inset 1px 1px 0 #a9b5bf,
    inset -1px -1px 0 #3c4650;
}
.tbtn.stop {
  width: calc(var(--u) * 68);
  background: #f2c3cc;
  color: #a01830;
  font-size: calc(var(--u) * 7.2);
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #a88;
}
.tbtn.stop.pressed {
  background: #e46a80;
  color: #fff;
}
.tag {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--u) * 37);
  margin-left: calc(var(--u) * 4);
  background: #d9e0e5;
  border: 1px solid #7d8b96;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--u) * 14);
  color: #222;
  white-space: nowrap;
  overflow: hidden;
}

/* ---------- Нижняя навигация ---------- */
.nav {
  grid-area: nav;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  padding: calc(var(--u) * 3) calc(var(--u) * 2) calc(var(--u) * 4)
    calc(var(--u) * 3);
  gap: calc(var(--u) * 10);
  min-width: 0;
}
.ngroup {
  display: flex;
  gap: calc(var(--u) * 4);
  min-width: 0;
}
.nbtn {
  width: calc(var(--u) * 60);
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 2);
}
.nlabel {
  display: block;
  width: 100%;
  font-size: calc(var(--u) * 8.4);
  line-height: calc(var(--u) * 12);
  color: #444f58;
  background: #c3ccd3;
  border: 1px solid #98a5b0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 calc(var(--u) * 2);
}
.nbtn.active .nlabel {
  background: #20d920;
  color: #f4fff4;
  border-color: #18a018;
}
.nicon {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #dfe4e8;
  border: 1px solid #5c6873;
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #8b98a3;
  min-height: 0;
}
.nlabel.beige {
  background: #f3dfc4;
  color: #c0702e;
  border-color: #c9ad8c;
}
/* Плитки иконок как на панели: без рамки, светлая, тёмная и розовая «в точку». */
.nicon.bare {
  background: none;
  border-color: transparent;
  box-shadow: none;
}
.nicon.light {
  background: #eceff1;
}
.nicon.dark {
  background: #59636c;
}
.nicon.dark svg {
  width: 90%;
  height: 90%;
}
.nicon.pink {
  background:
    radial-gradient(circle, #d58c8c 0.8px, transparent 1px) 0 0 / 3px 3px,
    #f2cdc8;
}
.nicon svg {
  width: 82%;
  height: 82%;
}
.nbtn:active .nicon {
  box-shadow:
    inset 2px 2px 0 #8b98a3,
    inset -1px -1px 0 #fff;
}

/* ---------- Узкие и вертикальные экраны ---------- */
@media (orientation: portrait), (max-width: 640px) {
  :root {
    --u: min(calc(100vw / 400), 2.2px);
  }
  html,
  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .hmi {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
      auto auto minmax(calc(var(--u) * 220), 52dvh)
      auto auto auto;
    grid-template-areas: "title" "clock" "trend" "side" "tools" "nav";
  }
  .title {
    border-right: 0;
    padding: calc(var(--u) * 5) 0;
  }
  .clock {
    padding: calc(var(--u) * 4) 0;
    border-top: 1px solid #2c3d66;
  }
  .side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: calc(var(--u) * 3);
  }
  .sbtns {
    grid-column: 1 / -1;
    flex-direction: row;
  }
  .sbtn {
    flex: 1;
  }
  .tools {
    flex-wrap: wrap;
    justify-content: center;
  }
  .tgap {
    display: none;
  }
  .tag {
    flex-basis: 100%;
    margin-left: 0;
  }
  .nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(calc(var(--u) * 70), 1fr));
    gap: calc(var(--u) * 6);
  }
  .ngroup {
    display: contents;
  }
  .nbtn {
    width: auto;
    height: calc(var(--u) * 66);
  }
}

/* Очень низкие окна в альбомной ориентации: допускаем вертикальную прокрутку. */
@media (orientation: landscape) and (max-height: 320px) {
  html,
  body {
    overflow-y: auto;
  }
}
