/* Очень умный дом — спокойный современный интерфейс: графит, стекло, тонкие линии. */
:root {
  --bg: #0b0d11;
  --card: #15181e;
  --card-2: #1b1f26;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #eef1f5;
  --muted: #8b93a1;
  --faint: #5d6573;
  --accent: #5b8def;
  --ok: #34c77b;
  --warn: #f5a524;
  --bad: #ff4d4f;
  --warm: #f5b54a;
  --radius: 16px;
  --font: Inter, "SF Pro Text", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  /* 6 камер 16:9 в один столбец на всю высоту */
  --gap: 10px;
  --cam-h: calc((100vh - 2 * var(--gap) - 5 * var(--gap)) / 6);
  --cam-w: calc(var(--cam-h) * 16 / 9);
  --bar-h: clamp(96px, 13vh, 128px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.ic { flex: none; display: block; }

#app { display: grid; grid-template-columns: var(--cam-w) 1fr; gap: var(--gap); height: 100vh; padding: var(--gap); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); position: relative; }
.glass { background: rgba(21, 24, 30, 0.78); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-color: var(--line-2); }
.card-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; display: flex; align-items: center; gap: 6px; }

.btn { background: var(--card-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 7px 14px; cursor: pointer; font-weight: 500; transition: background .15s; }
.btn:hover { background: #232832; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; padding: 11px 26px; font-size: 16px; }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: rgba(21,24,30,.78); border: 1px solid var(--line-2); cursor: pointer; color: var(--text); backdrop-filter: blur(10px); }
.icon-btn.active { background: var(--accent); border-color: transparent; }
.seg-ctl { display: flex; background: rgba(21,24,30,.78); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; backdrop-filter: blur(10px); }
.seg-ctl button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg-ctl button.active { background: #2a303b; color: var(--text); }

/* ---------- камеры ---------- */
.cams { display: grid; grid-template-rows: repeat(6, 1fr); gap: var(--gap); min-height: 0; }
.cam-tile { overflow: hidden; cursor: pointer; min-height: 0; background: #0f1115; }
.cam-tile .cam-media, .cam-tile .cam-media > * { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border: 0; }
.cam-tile .name { position: absolute; left: 8px; bottom: 8px; z-index: 2; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 8px; background: rgba(10,12,16,.6); backdrop-filter: blur(8px); display: flex; align-items: center; gap: 6px; }
.cam-tile .name::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); }
.cam-tile.empty { display: grid; place-items: center; color: var(--faint); font-size: 12px; background: transparent; border-style: dashed; }

/* ---------- центр ---------- */
#center { display: grid; grid-template-rows: 1fr var(--bar-h); gap: 10px; min-width: 0; min-height: 0; }
#map-wrap { overflow: hidden; min-height: 0; background: radial-gradient(ellipse at 50% 45%, #1a1e26 0%, #111318 70%); }
#map-stage { position: absolute; inset: 0; }
#map, #precip { position: absolute; inset: 0; width: 100%; height: 100%; }
#precip { pointer-events: none; }

#hud-tl { position: absolute; left: 20px; top: 16px; z-index: 3; display: flex; flex-direction: column; gap: 4px; }
#clock { display: flex; align-items: baseline; gap: 12px; }
#clock .time { font-size: clamp(30px, 4.4vh, 46px); font-weight: 300; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
#clock .date { color: var(--muted); font-size: 14px; }
#weather { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
#weather b { color: var(--text); font-weight: 500; font-size: 16px; }

#toolbar { display: flex; gap: 8px; margin-top: 10px; }
#edit-hint { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 3; font-size: 13px; color: var(--text); background: rgba(91,141,239,.2); border: 1px solid rgba(91,141,239,.5); padding: 7px 14px; border-radius: 10px; }

#feed { position: absolute; right: 14px; top: 14px; width: min(360px, 36%); max-height: 50%; padding: 14px 14px 10px; z-index: 3; display: flex; flex-direction: column; }
#feed ul { list-style: none; margin: 8px 0 0; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#feed li { display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: baseline; font-size: 13px; line-height: 1.35; padding: 7px 0; border-top: 1px solid var(--line); animation: slidein .3s ease; }
#feed li:first-child { border-top: 0; }
#feed li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); transform: translateY(-1px); }
#feed li.warn::before { background: var(--warn); }
#feed li.critical::before { background: var(--bad); }
#feed li.critical { color: #ffb4b0; }
#feed li .t { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
@keyframes slidein { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- угловые карточки ---------- */
.corner { position: absolute; bottom: 14px; z-index: 3; width: min(300px, 28%); padding: 12px 14px 10px; }
#corner-bl { left: 14px; }
#corner-br { right: 14px; }
.corner .rows { display: flex; flex-direction: column; margin-top: 6px; }
.corner .r { display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; align-items: center; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.corner .r:first-child { border-top: 0; }
.corner .r .ic { color: var(--muted); }
.corner .r .v { font-variant-numeric: tabular-nums; color: var(--text); display: flex; gap: 10px; align-items: center; }
.corner .r .v .m { color: var(--muted); }
.corner .r .n small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.corner .r.dim { color: var(--muted); }
.co2 { font-size: 12px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.scenes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.scenes button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line-2); cursor: pointer; font-size: 11px; color: var(--muted); }
.scenes button .ic { color: var(--text); }
.scenes button:active { background: var(--accent); color: #fff; }

/* ================= 3D: без окошек — текст и цифры прямо поверх сцены ================= */
body.proj-3d #feed, body.proj-3d .corner {
  background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; box-shadow: none; padding: 4px 6px;
}
body.proj-3d #feed { top: 22px; right: 22px; }
body.proj-3d #corner-bl { left: 22px; bottom: 18px; }
body.proj-3d #corner-br { right: 22px; bottom: 18px; }
body.proj-3d #feed, body.proj-3d .corner, body.proj-3d #hud-tl { text-shadow: 0 1px 2px rgba(0,0,0,.8), 0 0 12px rgba(11,13,17,.9); }
body.proj-3d #map-wrap .card-title { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; color: var(--faint); }
body.proj-3d #feed li, body.proj-3d .corner .r { border-top: 0; }
body.proj-3d #feed li:nth-child(n+6) { display: none; }
body.proj-3d #feed { text-align: right; }
body.proj-3d #feed .card-title { justify-content: flex-end; }
body.proj-3d #feed li { grid-template-columns: auto 1fr 8px; padding: 4px 0; }
body.proj-3d #feed li::before { order: 3; }
body.proj-3d #feed li .t { order: -1; }
body.proj-3d #corner-br .card-title { justify-content: flex-end; }
body.proj-3d #corner-br .r { grid-template-columns: 1fr auto 20px; text-align: right; }
body.proj-3d #corner-br .r > span:first-child { order: 3; }
body.proj-3d #corner-br .r .n { order: 1; }
body.proj-3d #corner-br .r .v { order: 2; min-width: 1.5em; justify-content: flex-end; }
body.proj-3d #corner-br .r .n small { max-width: none; }
body.proj-3d .corner .r .v { font-size: 15px; font-weight: 500; }
body.proj-3d .co2 { background: none !important; padding: 0; }
body.proj-3d .scenes { display: flex; justify-content: flex-end; gap: 4px; }
body.proj-3d .scenes button { background: none; border: 0; color: var(--muted); padding: 6px 8px; text-shadow: inherit; }
body.proj-3d .scenes button:hover { color: var(--text); }

/* ================= 2D: строгая сетка — у каждого блока своё окно ================= */
body.proj-2d #map-wrap {
  background: none; border: 0; border-radius: 0;
  display: grid; gap: 10px;
  grid-template-columns: 1fr clamp(260px, 24%, 340px);
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas: "hud feed" "stage feed" "stage climate" "stage now";
}
body.proj-2d #map-stage { position: relative; inset: auto; grid-area: stage; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 0; }
body.proj-2d #hud-tl { position: static; grid-area: hud; flex-direction: row; align-items: center; gap: 18px; padding: 2px 6px; flex-wrap: wrap; }
body.proj-2d #hud-tl #toolbar { margin: 0 0 0 auto; }
body.proj-2d #feed, body.proj-2d .corner { position: static; width: auto; max-height: none; background: var(--card); backdrop-filter: none; -webkit-backdrop-filter: none; border-color: var(--line); }
body.proj-2d #feed { grid-area: feed; min-height: 0; }
body.proj-2d #corner-bl { grid-area: climate; }
body.proj-2d #corner-br { grid-area: now; }
body.proj-2d #feed ul { flex: 1; -webkit-mask-image: linear-gradient(#000 85%, transparent); mask-image: linear-gradient(#000 85%, transparent); }
body.proj-2d #feed li:nth-child(n) { display: grid; }

/* ---------- комната ---------- */
#room-view { position: absolute; inset: 0; z-index: 5; background: #0f1115; border-radius: var(--radius); display: flex; flex-direction: column; padding: 16px; animation: fadein .2s; }
@keyframes fadein { from { opacity: 0; } }
#room-view header { display: flex; align-items: center; gap: 20px; padding-bottom: 14px; }
#room-view h2 { margin: 0; font-size: 22px; font-weight: 600; }
#room-view header .summary { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; }
.stat { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
.stat .ic { color: var(--muted); }
#room-view .body { flex: 1; display: grid; grid-template-columns: 1fr minmax(240px, 28%); gap: 14px; min-height: 0; }
#room-view .mosaic { display: grid; gap: 8px; min-height: 0; grid-auto-rows: 1fr; }
#room-view .mosaic .cam-media { position: relative; overflow: hidden; border-radius: 12px; background: #000; min-height: 0; }
#room-view .mosaic .cam-media > * { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border: 0; transition: transform .4s ease; }
#room-view .mosaic .nocam { display: grid; place-items: center; color: var(--faint); border: 1px dashed var(--line-2); border-radius: 12px; }
#room-view .devices { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.dev-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.dev-card .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--card-2); color: var(--muted); flex: none; }
.dev-card.on .ico { color: #fff; }
.dev-card .n { flex: 1; min-width: 0; }
.dev-card .n small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.swatches { display: flex; gap: 5px; margin-top: 8px; }
.swatches .sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); cursor: pointer; }
.toggle { width: 46px; height: 28px; border-radius: 14px; background: #2b313c; position: relative; cursor: pointer; flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.toggle.on { background: var(--ok); }
.toggle.on::after { left: 21px; }

/* фокус-режим: остаётся только комната */
body.focus #app { grid-template-columns: 1fr; gap: 0; padding: 0; }
body.focus .cams, body.focus #bar, body.focus #feed, body.focus #hud-tl, body.focus .corner { display: none; }
body.focus #center { grid-template-rows: 1fr 0; gap: 0; }
body.focus #map-wrap, body.focus #room-view { border: 0; border-radius: 0; }
body.focus #room-view .body { grid-template-columns: 1fr; }
body.focus #room-view .devices { display: none; }
body.focus #room-view .stat { font-size: 16px; padding: 7px 14px; }

/* ---------- нижняя панель ---------- */
#bar { display: grid; grid-template-columns: 1fr 1.35fr 1fr 1fr .9fr; gap: 10px; min-height: 0; }
.tile { padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; overflow: hidden; }
.tile .row { display: flex; align-items: center; gap: 10px; }
.tile .val { font-size: clamp(22px, 3.2vh, 30px); font-weight: 500; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile .val small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .ic-wrap { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--card-2); color: var(--muted); flex: none; }
.ic-wrap.hot { background: rgba(245,165,36,.15); color: var(--warn); }
.ic-wrap.ok { background: rgba(52,199,123,.14); color: var(--ok); }
.ic-wrap.bad { background: rgba(255,77,79,.15); color: var(--bad); }
.phases { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.phase { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.phase b { color: var(--text); font-weight: 500; font-size: 15px; font-variant-numeric: tabular-nums; }
.phase .meter { height: 4px; background: #262b34; border-radius: 2px; overflow: hidden; }
.phase .meter i { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.servers { display: flex; flex-direction: column; gap: 4px; font-size: 13px; overflow: hidden; }
.servers div { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.servers span.sub { margin-left: auto; }
#seg-security.armed { border-color: rgba(255,77,79,.45); }

/* ---------- тревога ---------- */
#critical { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(20,4,6,.72); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
#critical[hidden], #keypad[hidden], #login[hidden], #room-view[hidden] { display: none; }
#critical .box { text-align: center; max-width: 92vw; display: flex; flex-direction: column; gap: 18px; align-items: center; }
#critical .badge { width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; background: var(--bad); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,77,79,.6); } 70% { box-shadow: 0 0 0 36px rgba(255,77,79,0); } 100% { box-shadow: 0 0 0 0 rgba(255,77,79,0); } }
#critical h1 { font-size: clamp(30px, 5vw, 60px); margin: 0; font-weight: 600; letter-spacing: -0.02em; }
#critical .sub { color: #e7b6b4; font-size: 16px; }
#critical .cam { width: min(64vw, 860px); aspect-ratio: 16/9; position: relative; border-radius: 14px; overflow: hidden; }
#critical .cam:empty { display: none; }
#critical .cam .cam-media, #critical .cam .cam-media > * { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: cover; }
#critical .btn.primary { background: #fff; color: #111; }

#keypad, #login { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0,0,0,.6); backdrop-filter: blur(8px); }
#keypad .box, #login .box { padding: 26px; display: flex; flex-direction: column; gap: 16px; align-items: center; min-width: 320px; }
#keypad .display { display: flex; gap: 12px; height: 16px; }
#keypad .display i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--muted); }
#keypad .display i.f { background: var(--text); border-color: var(--text); }
#keypad .keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; }
#keypad .keys button { height: 72px; border-radius: 50%; font-size: 26px; font-weight: 300; background: var(--card-2); border: 1px solid var(--line-2); cursor: pointer; }
#keypad .keys button:active { background: #2c323d; }
#login h2 { margin: 0; font-weight: 600; }
#login p { margin: 0; color: var(--muted); }
#login input { font: inherit; font-size: 16px; padding: 11px 14px; background: var(--bg); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; width: 100%; outline: none; }
#login input:focus { border-color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 34px); transform: translate(-50%, 8px); z-index: 70; background: rgba(30,34,42,.95); backdrop-filter: blur(10px); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 18px; font-size: 15px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* планшеты 1280×800 и подобные */
@media (max-width: 1440px) {
  html, body { font-size: 13px; }
  :root { --gap: 8px; }
  #center, #bar { gap: 8px; }
  #feed { width: min(300px, 34%); padding: 10px 12px 6px; }
  #feed li { padding: 5px 0; font-size: 12px; }
  #feed li:nth-child(n+4) { display: none; }
  .corner { width: 240px; padding: 10px 12px 8px; }
  .corner .r { font-size: 12px; gap: 8px; padding: 4px 0; }
  .corner .r .n small { display: none; }
  .scenes button { font-size: 10px; padding: 5px 2px; }
  #clock .time { font-size: 32px; }
  #toolbar { margin-top: 6px; }
  .tile { padding: 10px 12px; gap: 4px; }
  .tile .val { font-size: 22px; }
  .tile .val small { font-size: 11px; }
  .tile .ic-wrap { width: 28px; height: 28px; border-radius: 8px; }
  .tile .ic-wrap .ic { width: 15px; height: 15px; }
  .phases { gap: 8px; }
  .phase b { font-size: 13px; white-space: nowrap; }
  .phase span { white-space: nowrap; }
  .servers span.sub { display: none; }
  #bar { grid-template-columns: 1fr 1.4fr 1fr .9fr 1fr; }
  #seg-security .val { font-size: 15px !important; }
  #seg-security .btn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #seg-boiler .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.proj-2d #hud-tl { flex-wrap: nowrap; gap: 12px; }
  body.proj-2d #clock .date { display: none; }
  body.proj-2d #clock .time { font-size: 28px; }
}

@media (max-width: 900px) and (orientation: portrait) {
  #app { grid-template-columns: 1fr; }
  .cams { display: none; }
  #bar { grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(90px, auto); }
  #center { grid-template-rows: 1fr auto; }
}
