:root {
  --bg: #0b1220;
  --bg-elev: #121b2f;
  --bg-card: #17233a;
  --line: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --orange: #f97316;
  --disaster: #ef4444;
  --high: #f97316;
  --average: #eab308;
  --warning: #facc15;
  --info: #38bdf8;
  --ok: #22c55e;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

body { padding: 0; }

.app {
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 12px calc(20px + var(--safe-bottom));
  background: radial-gradient(900px 420px at 10% -10%, #1e293b 0%, var(--bg) 48%);
  overflow-x: hidden;
}

.app-head {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0 -12px 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, #0b1220 72%, rgba(11, 18, 32, 0.94));
  backdrop-filter: blur(12px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.brand > div { min-width: 0; }

.brand img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: #243049;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn.primary { background: var(--orange); color: #111827; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.compact { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn.icon {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  flex-shrink: 0;
}
.btn.icon svg { width: 22px; height: 22px; }
.btn.icon[aria-expanded="true"] { background: #fff; color: #0b1220; }
.btn.icon.has-filters { box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.55); }
.icon-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--orange);
  color: #111827;
  font-size: 0.68rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  line-height: 1;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.38);
}

.panel {
  margin-top: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
  max-height: min(72vh, 640px);
  overflow: auto;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sheet-head h2 { margin: 0; font-size: 0.95rem; }

.settings-list { display: grid; gap: 8px; }
.settings-list .btn {
  width: 100%;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
}

.setting-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.setting-block legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
}
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.92rem;
}
.choice em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}
.hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.banner {
  background: #3f1d1d;
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.banner.warn {
  background: #3b2a12;
  border-color: rgba(249, 115, 22, 0.4);
  color: #fed7aa;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  min-height: 40px;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.active {
  background: #fff;
  color: #0b1220;
  border-color: #fff;
}

.search,
.filter-field select,
.filter-field input,
.filter-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-size: 16px;
  font-family: inherit;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.filter-field {
  display: grid;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.result-count {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.sev-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.sev-bar span {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}

.list { display: grid; gap: 10px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
  width: 100%;
  min-width: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.card.resolved { opacity: 0.72; }
.card.fresh {
  --fresh-fg: #f97316;
  --fresh-glow: rgba(249, 115, 22, 0.35);
  --fresh-fill: rgba(249, 115, 22, 0.2);
  animation: fresh-blink 1.15s ease-in-out infinite;
}
@keyframes fresh-blink {
  0%, 100% {
    box-shadow: 0 0 0 1px var(--fresh-glow);
    background: var(--bg-card);
  }
  50% {
    box-shadow: 0 0 0 2px var(--fresh-fg), 0 0 18px var(--fresh-glow);
    background: var(--fresh-fill);
  }
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.card-top-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.card-host {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  max-width: 58%;
}

.card-when {
  flex-shrink: 0;
  font-size: 0.75rem;
}

.card-flags {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.sev {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}
.sev.disaster { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.sev.high { background: rgba(249, 115, 22, 0.18); color: #fdba74; }
.sev.average { background: rgba(234, 179, 8, 0.16); color: #fde68a; }
.sev.warning { background: rgba(250, 204, 21, 0.16); color: #fef08a; }
.sev.info, .sev.not_classified { background: rgba(56, 189, 248, 0.16); color: #bae6fd; }

.flag {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}
.flag.ack { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.flag.local { background: rgba(249, 115, 22, 0.18); color: #fdba74; }
.flag.suppress { background: rgba(168, 85, 247, 0.16); color: #d8b4fe; }
.flag.resolved { background: rgba(56, 189, 248, 0.16); color: #bae6fd; }

.card h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.meta, .desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.4rem;
  align-items: center;
}
.meta .dot { opacity: 0.5; }

.tag {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  padding: 0;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag.group-chip {
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: var(--chip-bg);
  color: var(--chip-fg);
}
.tag.group-chip.active {
  box-shadow: inset 0 0 0 1.5px var(--chip-fg);
}
.tag.host-tag {
  color: #e2e8f0;
  font-size: 0.82rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.tag.host-tag.active {
  color: var(--orange);
  text-decoration-thickness: 2px;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 18, 32, 0.92);
}

.login-card {
  width: min(100%, 380px);
  background: #fff;
  color: #111827;
  border-radius: 18px;
  padding: 1.4rem;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
.login-card img { border-radius: 12px; justify-self: center; }
.login-card h2 { margin: 0; text-align: center; font-size: 1.05rem; line-height: 1.3; }
.login-card label { display: grid; gap: 4px; font-size: 0.85rem; color: #4b5563; }
.login-card input {
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 16px;
}
.login-error { margin: 0; color: #b91c1c; font-size: 0.85rem; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.muted { color: #6b7280; }

dialog.sheet {
  border: 0;
  border-radius: 18px 18px 0 0;
  background: #121b2f;
  color: var(--text);
  width: min(100%, 560px);
  max-width: 100%;
  max-height: min(88dvh, 820px);
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
  margin: auto 0 0;
  display: none;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}
dialog.sheet[open] { display: flex; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.sheet h3 { margin: 0 0 8px; font-size: 0.85rem; color: var(--muted); }

.ack-list {
  display: grid;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
}
.ack-item {
  background: #0b1220;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
}
.ack-item b { color: #e2e8f0; }
.ack-item span { color: var(--muted); }

.suppress-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.btn.resolve { background: var(--ok); color: #052e16; }
.btn.local { background: #243049; color: #e2e8f0; border: 1px solid var(--line); }
.zabbix-link {
  text-align: center;
  text-decoration: none;
  display: block;
}

html.layout-desktop .app { max-width: 1100px; margin: 0 auto; }
html.layout-desktop .list {
  grid-template-columns: 1fr;
}
html.layout-desktop .card {
  grid-template-columns: 110px 1fr auto;
  align-items: start;
}
html.layout-desktop .card h2 { grid-column: 2; }
html.layout-desktop .card .meta { grid-column: 2; }
html.layout-desktop dialog.sheet {
  border-radius: 18px;
  margin: auto;
}

html.layout-mobile body {
  display: flex;
  justify-content: center;
  background: #070b14;
}
html.layout-mobile .login-gate,
html.layout-mobile .menu-backdrop {
  left: 50%;
  right: auto;
  width: 100%;
  max-width: 430px;
  transform: translateX(-50%);
}

@media (max-width: 430px) {
  html.layout-mobile body {
    display: block;
    background: var(--bg);
  }
  html.layout-mobile .app { max-width: none; }
  html.layout-mobile .login-gate,
  html.layout-mobile .menu-backdrop {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    transform: none;
  }
}
