@font-face {
  font-family: "Material Symbols Rounded";
  src: url("material-symbols-rounded.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

:root {
  color-scheme: dark light;
  --bg: var(--tg-theme-bg-color, #121720);
  --surface: var(--tg-theme-secondary-bg-color, #1c2430);
  --surface-raised: #202936;
  --text: var(--tg-theme-text-color, #f4f7fb);
  --muted: var(--tg-theme-hint-color, #a9b2c2);
  --border: #344052;
  --track: #2a3443;
  --good: #29b57b;
  --good-soft: rgba(41, 181, 123, 0.12);
  --warn: #e6a23c;
  --warn-soft: rgba(230, 162, 60, 0.12);
  --bad: #ef6068;
  --bad-soft: rgba(239, 96, 104, 0.12);
  --unknown: #8c98aa;
  --unknown-soft: rgba(140, 152, 170, 0.12);
  --accent: var(--tg-theme-button-color, #4f7df3);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --radius-lg: 19px;
  --radius-md: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--tg-theme-bg-color, #eef2f7);
    --surface: var(--tg-theme-secondary-bg-color, #ffffff);
    --surface-raised: #f8fafc;
    --text: var(--tg-theme-text-color, #16202d);
    --muted: var(--tg-theme-hint-color, #657184);
    --border: #d9e0e9;
    --track: #e8edf3;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-font-smoothing: antialiased; }
button { font: inherit; }
.material-symbols-rounded {
  font-family: "Material Symbols Rounded";
  font-weight: normal;
  font-style: normal;
  font-size: 22px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-feature-settings: "liga";
}

.app-shell {
  width: min(100%, 780px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + var(--tg-content-safe-area-inset-top, env(safe-area-inset-top))) 12px
    calc(86px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom)));
}

.monitor-header {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  padding: 10px 8px 13px;
  border-bottom: 1px solid var(--border);
}
.server-mark, .icon-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--muted);
}
.server-mark { position: relative; width: 48px; height: 48px; border-radius: 14px; }
.server-mark .material-symbols-rounded { font-size: 25px; }
.presence-dot { position: absolute; right: 6px; bottom: 6px; width: 8px; height: 8px; border: 2px solid var(--surface-raised); border-radius: 50%; background: var(--unknown); }
.server-identity { min-width: 0; }
.server-identity h1 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -0.02em; }
.server-line { display: flex; align-items: center; gap: 4px; min-width: 0; margin-top: 5px; color: var(--muted); font-size: 12px; }
.server-line span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-icon { font-size: 16px; }
.icon-button { width: 42px; height: 42px; padding: 0; border-radius: 12px; cursor: pointer; }
.icon-button:active { transform: scale(0.96); }
.icon-button[disabled] { opacity: 0.55; cursor: wait; }

.banner { margin: 12px 2px 0; padding: 11px 13px; border: 1px solid rgba(239, 96, 104, 0.28); border-radius: 13px; background: var(--bad-soft); color: var(--bad); font-size: 12px; line-height: 1.4; }
.hidden { display: none !important; }
.view { display: none; padding-top: 14px; }
.view.active { display: block; }
.summary-strip { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 0 5px 12px; }
.summary-strip strong, .summary-label { display: block; }
.summary-strip strong { margin-top: 3px; font-size: 13px; }
.summary-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.summary-right { text-align: right; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.metric-card, .storage-card, .status-card, .list-row, .project-card, .empty-state {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 9px 28px rgba(0, 0, 0, 0.08);
}
.metric-card { min-width: 0; min-height: 154px; padding: 13px; border-radius: var(--radius-lg); }
.metric-head { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.metric-icon { display: grid; flex: 0 0 30px; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--unknown-soft); color: var(--unknown); font-size: 18px; }
.metric-title { min-width: 0; }
.metric-title strong, .metric-title span { display: block; }
.metric-title strong {
  display: -webkit-box;
  min-height: 29px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.metric-title span { margin-top: 2px; color: var(--unknown); font-size: 10px; }
.metric-value-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 14px; }
.metric-value-row strong { color: var(--unknown); font-size: clamp(22px, 6vw, 26px); font-weight: 500; line-height: 1; letter-spacing: -0.04em; white-space: nowrap; }
.metric-value-row span { overflow: hidden; color: var(--muted); font-size: 10px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 5px; margin: 12px 0 9px; overflow: hidden; border-radius: 999px; background: var(--track); }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--unknown); transition: width 220ms ease; }
.metric-detail { margin: 0; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }

.storage-card { margin-top: 9px; padding: 13px; border-radius: var(--radius-lg); }
.storage-head, .storage-name, .storage-values { display: flex; align-items: center; }
.storage-head { justify-content: space-between; gap: 10px; }
.storage-name { min-width: 0; gap: 8px; }
.storage-name .material-symbols-rounded { color: var(--unknown); font-size: 19px; }
.storage-name strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.storage-values { min-width: 0; gap: 9px; }
.storage-values span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.storage-values strong { color: var(--unknown); font-size: 20px; font-weight: 500; }
.storage-card .progress { margin-bottom: 0; }

.status-grid { display: grid; grid-template-columns: 1fr; gap: 9px; margin-top: 9px; }
.status-card { min-width: 0; padding: 13px; border-radius: var(--radius-lg); }
.status-card-head { display: grid; grid-template-columns: 19px minmax(0, 1fr) auto; align-items: center; gap: 7px; }
.status-card-head .material-symbols-rounded { color: var(--unknown); font-size: 18px; }
.status-card-head strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.status-card-head span:last-child { color: var(--unknown); font-size: 10px; white-space: nowrap; }
.status-card-value { display: block; margin-top: 12px; color: var(--unknown); font-size: 18px; font-weight: 500; }
.status-card p { margin: 4px 0 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.status-healthy .metric-icon, .status-healthy .presence-dot { background: var(--good); color: #fff; }
.status-healthy .metric-title span, .status-healthy .metric-value-row strong, .status-healthy .storage-name .material-symbols-rounded, .status-healthy .storage-values strong, .status-healthy .status-card-head .material-symbols-rounded, .status-healthy .status-card-head span:last-child, .status-healthy .status-card-value { color: var(--good); }
.status-healthy .progress span { background: var(--good); }
.status-warning .metric-icon, .status-warning .presence-dot { background: var(--warn); color: #1c2430; }
.status-warning .metric-title span, .status-warning .metric-value-row strong, .status-warning .storage-name .material-symbols-rounded, .status-warning .storage-values strong, .status-warning .status-card-head .material-symbols-rounded, .status-warning .status-card-head span:last-child, .status-warning .status-card-value { color: var(--warn); }
.status-warning .progress span { background: var(--warn); }
.status-critical .metric-icon, .status-critical .presence-dot, .status-offline .metric-icon, .status-offline .presence-dot { background: var(--bad); color: #fff; }
.status-critical .metric-title span, .status-critical .metric-value-row strong, .status-critical .storage-name .material-symbols-rounded, .status-critical .storage-values strong, .status-critical .status-card-head .material-symbols-rounded, .status-critical .status-card-head span:last-child, .status-critical .status-card-value, .status-offline .status-card-head span:last-child, .status-offline .status-card-value { color: var(--bad); }
.status-critical .progress span, .status-offline .progress span { background: var(--bad); }

h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 23px; letter-spacing: -0.02em; }
h3 { margin: 22px 3px 9px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em; }
.section-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.stack-list, .card-list, .timeline { display: grid; gap: 8px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; padding: 11px 12px; border-radius: var(--radius-md); }
.list-main { min-width: 0; }
.list-main strong, .list-main small { display: block; }
.list-main strong { font-size: 13px; }
.list-main small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.state-dot { flex: 0 0 auto; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.state-dot.status-healthy { color: var(--good); background: var(--good-soft); }
.state-dot.status-warning { color: var(--warn); background: var(--warn-soft); }
.state-dot.status-critical, .state-dot.status-offline { color: var(--bad); background: var(--bad-soft); }
.state-dot.status-unknown { color: var(--unknown); background: var(--unknown-soft); }

.filter-row { display: flex; gap: 7px; margin: 15px 0 13px; overflow-x: auto; scrollbar-width: none; }
.filter { min-height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 11px; white-space: nowrap; }
.filter.active { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.event { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 10px; padding: 11px 3px; }
.event-mark { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--unknown); }
.event[data-kind="critical"] .event-mark { background: var(--bad); }
.event[data-kind="warning"] .event-mark { background: var(--warn); }
.event[data-kind="recovery"] .event-mark { background: var(--good); }
.event strong, .event time { display: block; }
.event strong { font-size: 13px; }
.event p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.event time { margin-top: 5px; color: var(--muted); font-size: 10px; }

.project-card { padding: 14px; border-radius: var(--radius-lg); }
.project-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.project-head strong { font-size: 13px; }
.project-card p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.cabinet-button { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 44px; margin-top: 11px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.empty-state { padding: 20px 14px; border-radius: var(--radius-lg); color: var(--muted); text-align: center; font-size: 11px; }

.bottom-nav {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 0;
  width: min(100%, 780px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 7px 6px calc(7px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom)));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.nav-button { display: grid; justify-items: center; gap: 3px; min-width: 0; min-height: 49px; padding: 4px 1px; border: 0; background: transparent; color: var(--muted); font-size: 9px; }
.nav-button .material-symbols-rounded { font-size: 21px; }
.nav-button.active { color: var(--good); font-weight: 700; }

@media (min-width: 600px) {
  .app-shell { padding-left: 18px; padding-right: 18px; }
  .status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-card { min-height: 162px; }
}

@media (max-width: 359px) {
  .metric-grid { grid-template-columns: 1fr; }
  .storage-head { align-items: flex-start; flex-direction: column; }
  .storage-values { justify-content: space-between; width: 100%; }
  .nav-button { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
