:root {
  --bg: #000;
  --panel: #0c0d10;
  --line: #1c1f25;
  --chip: #15171c;
  --text: #eceef1;
  --muted: #8b919b;
  --dim: #545a63;
  --ok: #3ddc84;
  --warn: #ffb020;
  --bad: #ff4d4f;
  --off: #474c54;
  --series: #3987e5;  /* линии графиков: слот 1 палитры, проверен валидатором на фоне #0c0d10 */
  --mono: "JetBrains Mono", "Roboto Mono", "Droid Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

#root {
  /* fixed + inset, а не 100vh/100%: если WebView отдаст странице нулевую высоту, раскладка не схлопнется */
  position: fixed;
  inset: 0;
  padding: 10px;
  display: grid;
  gap: 8px;
  transition: transform 2s ease;
}

.hero { grid-area: hero; }
.cat-panel { grid-area: cat; }
.server { grid-area: server; }
.sites { grid-area: sites; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  min-height: 0;
  overflow: hidden;
}

h2 {
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.cmd b, .prompt { color: var(--ok); font-weight: 700; }

.empty { color: var(--dim); font-size: 13px; }

/* ── Часы и погода ─────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "clock weather" "status weather";
  align-items: center;
  gap: 8px 12px;
}
.clock { grid-area: clock; min-width: 0; }
.weather { grid-area: weather; }
.status-row { grid-area: status; }
#time { font-size: 64px; font-weight: 300; line-height: 1; letter-spacing: -.02em; }
#date { margin-top: 6px; color: var(--muted); font-size: 14px; }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; }
.status { padding: 3px 9px; border-radius: 999px; background: var(--chip); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }
.status.off { color: var(--muted); }
.w-place { margin-bottom: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }

.weather { text-align: right; min-width: 0; }
.w-now { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 34px; font-weight: 300; line-height: 1; }
.w-icon { font-size: 28px; }
.w-desc { margin-top: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.w-days { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.w-day b { color: var(--text); font-weight: 500; }

/* ── Котик ─────────────────────────────────────── */
/* Пиксель котика = --cat-cell; кадры разной ширины, cat.js сам задаёт размер svg. */
.cat-panel {
  --cat-cell: 7px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
}
.cat-panel.panic { border-color: var(--bad); animation: alarm 1.2s ease-in-out infinite; }

.bubble {
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  padding: 9px 13px;
  background: #1a1d23;
  border-radius: 14px 14px 14px 4px;
  font-size: 15px;
  line-height: 1.3;
}
.cat-panel.panic .bubble { background: #3a1416; }

.cat-stage { position: relative; flex: none; height: calc(16 * var(--cat-cell)); }
.cat-pos { position: absolute; bottom: 0; left: 0; }
.cat-flip { transform-origin: center; }
.cat-svg { display: block; transform-origin: 50% 100%; animation: breathe 3s ease-in-out infinite alternate; }
.cat-panel.sleep .cat-svg { animation-duration: 5s; }
.cat-panel.panic .cat-svg { animation: shake .25s linear infinite; }
.cat-svg.cat-jump { animation: jump .5s ease-out; }

.cat-zzz { position: absolute; right: -4px; top: -18px; display: none; color: var(--muted); font-size: 18px; animation: zzz 3s ease-in-out infinite; }
.cat-zzz small { margin-left: 2px; font-size: .7em; }
.cat-pos.napping .cat-zzz { display: block; }

.cat-heart { position: absolute; left: 40%; top: -6px; color: #ff6b81; font-size: 22px; pointer-events: none; animation: heart 1.2s ease-out forwards; }

.cat-laptop { position: absolute; bottom: 0; left: calc(2 * var(--cat-cell)); z-index: 2; }
.cat-code {
  position: absolute;
  bottom: calc(8 * var(--cat-cell));
  z-index: 3;
  color: var(--ok);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  animation: code-up 1.5s ease-out forwards;
}
.cat-mug { position: absolute; bottom: 0; left: calc(17 * var(--cat-cell)); }
.cat-mug svg { display: block; }
.cat-mug i {
  position: absolute;
  bottom: calc(6 * var(--cat-cell));
  left: calc(1 * var(--cat-cell));
  width: var(--cat-cell);
  height: var(--cat-cell);
  background: #9aa0a6;
  opacity: 0;
  animation: steam 2s ease-out infinite;
}
.cat-mug i + i { left: calc(3 * var(--cat-cell)); animation-delay: 1s; }
.cat-flame { position: absolute; bottom: 0; display: none; transform-origin: 50% 100%; animation: flicker .35s ease-in-out infinite alternate; }
.cat-flame-left { left: calc(-6 * var(--cat-cell)); }
.cat-flame-right { left: calc(18 * var(--cat-cell)); animation-delay: .17s; }
.cat-pos.on-fire .cat-flame { display: block; }
.cat-ball { position: absolute; bottom: 0; width: calc(4 * var(--cat-cell)); height: calc(4 * var(--cat-cell)); }
.cat-ball svg { display: block; width: 100%; height: 100%; }
.cat-ball.rolling svg { animation: spin .9s cubic-bezier(.2, .7, .3, 1); }

/* ── Сервер ────────────────────────────────────── */
.srv-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.srv-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 17px; font-weight: 500; }
.srv-host { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srv-uptime { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.srv-host { font-family: var(--mono); }
.server.stale .meters, .server.stale .row, .server.stale .charts { opacity: .35; }

.meters { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.meter-label { color: var(--muted); min-width: 30px; }
.meter-val { text-align: right; white-space: nowrap; }
.bar { height: 6px; background: #1b1e24; border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width 1s ease; }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.row-label { min-width: 30px; color: var(--muted); font-size: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; background: var(--chip); border-radius: 999px; font-size: 12.5px; white-space: nowrap; }
.chip.dim { color: var(--dim); }

.dot { flex: none; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); animation: blink 1s steps(2) infinite; }

/* ── Графики ───────────────────────────────────── */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.chart { min-width: 0; }
.chart-title { color: var(--muted); font-size: 12px; }
.chart-value { margin: 1px 0 5px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-plot { position: relative; }
.chart-plot svg { display: block; width: 100%; height: 44px; }
.chart-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--series); opacity: .16; }
.chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart-marker { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--text); opacity: .7; pointer-events: none; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 3px; color: var(--dim); font-size: 10.5px; }

/* ── Сайты ─────────────────────────────────────── */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.site { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; background: var(--chip); border-radius: 10px; font-size: 13.5px; }
.site .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site .age { color: var(--dim); font-size: 11.5px; white-space: nowrap; }
.site.down { background: rgba(255, 77, 79, .16); box-shadow: inset 0 0 0 1px var(--bad); }
.site.down .age { color: var(--bad); }
.site.pending { background: rgba(255, 176, 32, .1); }

.hub-offline {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: #3a1416;
  color: #ffb3b4;
  border-radius: 999px;
  font-size: 13px;
}

/* ── Подробности по тапу и демо-панель ─────────── */
.hero, .server, .sites { cursor: pointer; }
.site:active, .panel:active { filter: brightness(1.25); }

.popover { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .6); }
.popover-card { width: min(420px, 100%); padding: 18px 20px; background: #15171c; border: 1px solid var(--line); border-radius: 18px; }
.popover-card h3 { margin: 0 0 10px; font-size: 20px; font-weight: 500; }
.popover-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.popover-card dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 15px; }
.popover-card dt { color: var(--muted); }
.popover-card dd { display: flex; align-items: center; gap: 8px; margin: 0; }

.dock {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 40;
  display: flex;
  gap: 4px;
  padding: 5px;
  transform: translateX(-50%);
  background: rgba(21, 23, 28, .92);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
.dock button {
  padding: 9px 14px;
  background: none;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
}
.dock button.active { background: #262a31; color: var(--text); }

/* ── Раскладки ─────────────────────────────────── */
@media (orientation: portrait) {
  /* место под графики сервера: статус одной строкой, прогноз на 3 дня — по тапу на погоду */
  .hero { grid-template-areas: "clock weather" "status status"; }
  .status-row { flex-wrap: nowrap; }
  .w-days { display: none; }
  .cat-panel { --cat-cell: 6px; gap: 8px; }
  .chart-plot svg { height: 32px; }
  .charts { margin-top: 10px; }
  #root {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas: "hero" "cat" "server" "sites";
  }
}

@media (orientation: landscape) {
  #root {
    grid-template-columns: .95fr 1.15fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "hero server sites" "cat server sites";
  }
  .hero { grid-template-areas: "clock status" "weather weather"; }
  .status-row { flex-direction: column; align-items: flex-end; }
  #time { font-size: 50px; }
  #date { font-size: 12.5px; }
  .weather { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; text-align: left; }
  .w-place { flex-basis: 100%; margin: 0; }
  .w-now { font-size: 26px; }
  .w-icon { font-size: 22px; }
  .w-desc { margin-top: 0; }
  .w-days { display: none; }
  .cat-panel { --cat-cell: 5.5px; }
  .bubble { padding: 7px 11px; font-size: 13px; line-height: 1.25; }
  .site-grid { grid-template-columns: 1fr; }
}

/* ── Экраны по команде Алисы ───────────────────── */
/* Идут после раскладок: body[data-view] перебивает #root из медиазапросов. */
#blackout { position: fixed; inset: 0; z-index: 100; display: none; background: #000; }
body.screen-off #blackout { display: block; }

body[data-view="server"] #root,
body[data-view="sites"] #root { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body[data-view="server"] #root { grid-template-areas: "server"; }
body[data-view="sites"] #root { grid-template-areas: "sites"; }
body[data-view="server"] :is(.hero, .cat-panel, .sites),
body[data-view="sites"] :is(.hero, .cat-panel, .server),
body[data-view="clock"] :is(.server, .sites) { display: none; }
body[data-view="server"] .server { zoom: 1.45; }
body[data-view="sites"] .sites { zoom: 1.5; }

body[data-view="clock"] #root { grid-template-columns: 1fr; grid-template-rows: auto 1fr; grid-template-areas: "hero" "cat"; }
body[data-view="clock"] .hero {
  grid-template-columns: 1fr;
  grid-template-areas: "clock" "status" "weather";
  justify-items: center;
  align-content: center;
  text-align: center;
  padding: 28px 14px;
}
body[data-view="clock"] .status-row { flex-direction: row; justify-content: center; }
body[data-view="clock"] #time { font-size: 120px; }
body[data-view="clock"] .weather { text-align: center; }
body[data-view="clock"] :is(.w-now, .w-days) { justify-content: center; }
body[data-view="clock"] .cat-panel { --cat-cell: 10px; }

@media (orientation: landscape) {
  body[data-view="server"] .server { zoom: 1.15; }
  body[data-view="sites"] .sites { zoom: 1.2; }
  body[data-view="sites"] .site-grid { grid-template-columns: 1fr 1fr; }
  body[data-view="clock"] #root { grid-template-columns: 1.3fr 1fr; grid-template-rows: 1fr; grid-template-areas: "hero cat"; }
  body[data-view="clock"] #time { font-size: 110px; }
  body[data-view="clock"] .weather { display: block; }
  body[data-view="clock"] .w-days { display: flex; }
}

/* ── Анимации ──────────────────────────────────── */
@keyframes breathe { from { transform: scaleY(1); } to { transform: scaleY(1.04); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
@keyframes alarm { 0%, 100% { box-shadow: 0 0 0 rgba(255, 77, 79, 0); } 50% { box-shadow: 0 0 24px rgba(255, 77, 79, .55); } }
@keyframes blink { 50% { opacity: .3; } }
@keyframes code-up { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-36px); } }
@keyframes steam { 0% { opacity: 0; transform: translateY(0); } 30% { opacity: .7; } 100% { opacity: 0; transform: translateY(-18px); } }
@keyframes flicker { from { transform: scaleY(1) skewX(0); } to { transform: scaleY(1.15) skewX(4deg); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-28%) scaleY(1.06); } 70% { transform: translateY(0) scaleY(.92); } }
@keyframes heart { from { opacity: 1; transform: translateY(0) scale(.6); } to { opacity: 0; transform: translateY(-48px) scale(1.3); } }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(720deg); } }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 6px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(8px, -14px); } }
