:root {
  --bg: #070910;
  --bg-glow-1: rgba(79, 140, 255, 0.18);
  --bg-glow-2: rgba(124, 92, 255, 0.14);
  --surface: #10141e;
  --surface-2: #161c28;
  --surface-3: #1f2634;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8ecf4;
  --muted: #8892a6;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --up: #35d07f;
  --warn: #ffb347;
  --down: #ff5f57;
  --unknown: #5c657a;
  --pin: #ffc857;
  --radius: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --tile-pad: 14px;
  --tile-min: 236px;
  --icon-size: 40px;
}

:root[data-theme='light'] {
  --bg: #f2f5fa;
  --bg-glow-1: rgba(79, 140, 255, 0.14);
  --bg-glow-2: rgba(124, 92, 255, 0.1);
  --surface: #ffffff;
  --surface-2: #f4f7fc;
  --surface-3: #e7edf6;
  --border: rgba(16, 24, 40, 0.09);
  --border-strong: rgba(16, 24, 40, 0.16);
  --text: #0e1420;
  --muted: #5d6a80;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --up: #12a05f;
  --down: #e03b34;
  --unknown: #97a1b3;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
}

:root[data-density='compact'] {
  --tile-pad: 9px;
  --tile-min: 190px;
  --icon-size: 32px;
  --radius: 13px;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Мягкая подсветка фона — два пятна, которые не мешают читать текст. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 12% -8%, var(--bg-glow-1), transparent 65%),
    radial-gradient(800px 450px at 92% 4%, var(--bg-glow-2), transparent 60%);
  pointer-events: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* --- шапка --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f8cff, #7c5cff);
  box-shadow: 0 4px 14px rgba(79, 140, 255, 0.4);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 520px;
  margin: 0 auto;
}

.search-wrap svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 10px 44px 10px 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

#search:focus {
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-hint {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, #4f8cff, #6d6bff);
  border-color: transparent;
  color: #fff;
  font-weight: 560;
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.32);
}

.btn-primary:hover {
  filter: brightness(1.08);
  border-color: transparent;
}

.btn-icon {
  padding: 9px;
  width: 38px;
  justify-content: center;
}

/* --- меню --- */

.menu {
  position: relative;
}

.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  box-shadow: var(--shadow);
  display: none;
}

.menu.open .menu-list {
  display: block;
  animation: pop 0.14s ease;
}

.menu-list button,
.menu-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: none;
  border: 0;
  border-radius: 9px;
  color: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-list button:hover,
.menu-list a:hover {
  background: var(--surface-2);
}

.menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-5px) scale(0.98);
  }
}

/* --- панель сводки --- */

.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 26px 0;
}

.stat {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  min-width: 148px;
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 78%, var(--bg)));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}

.stat-ico {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: var(--surface-3);
  font-size: 15px;
}

.stat-ico.up {
  background: color-mix(in srgb, var(--up) 18%, transparent);
  color: var(--up);
}

.stat-ico.down {
  background: color-mix(in srgb, var(--down) 18%, transparent);
  color: var(--down);
}

.stat-ico.warn {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
}

.stat-value {
  display: block;
  font-size: 19px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat.clickable {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
}

.stat.clickable:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.stat.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.stat-check {
  margin-left: auto;
  gap: 10px;
}

.stat-check .btn {
  padding: 7px 12px;
  font-size: 13.5px;
}

.stat-check .btn.busy {
  opacity: 0.6;
  pointer-events: none;
}

/* --- доска --- */

.board {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 26px 90px;
}

.group {
  margin-bottom: 32px;
}

.group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.group-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: hsl(var(--hue) 70% 55% / 0.13);
  border: 1px solid hsl(var(--hue) 70% 60% / 0.26);
  color: hsl(var(--hue) 80% 76%);
}

:root[data-theme='light'] .group-title {
  color: hsl(var(--hue) 65% 34%);
  background: hsl(var(--hue) 70% 55% / 0.11);
}

.group-head .count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.group-head .line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, hsl(var(--hue) 70% 60% / 0.28), transparent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: 11px;
  min-height: 10px;
}

.grid.drop-target {
  outline: 2px dashed hsl(var(--hue) 70% 60% / 0.6);
  outline-offset: 8px;
  border-radius: var(--radius);
}

/* --- плитка --- */

.tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: var(--tile-pad);
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 80%, var(--bg)));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: tile-in 0.28s ease backwards;
  animation-delay: calc(var(--i, 0) * 18ms);
  transition: transform 0.16s ease, border-color 0.16s, box-shadow 0.16s, background 0.16s;
}

.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: radial-gradient(120% 100% at 0% 0%, hsl(var(--hue) 80% 60% / 0.12), transparent 55%);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}

.tile:hover {
  transform: translateY(-3px);
  border-color: hsl(var(--hue) 70% 60% / 0.45);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28), 0 0 0 1px hsl(var(--hue) 70% 60% / 0.12);
}

.tile:hover::after {
  opacity: 1;
}

.tile.dragging {
  opacity: 0.35;
  transform: scale(0.98);
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

.tile-hit {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: var(--radius);
}

.tile-hit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tile-icon {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--icon-size);
  height: var(--icon-size);
  border-radius: 11px;
  background: hsl(var(--hue) 45% 50% / 0.14);
  border: 1px solid hsl(var(--hue) 60% 60% / 0.16);
  overflow: hidden;
  font-size: 15px;
  font-weight: 650;
  color: #fff;
}

.tile-icon img {
  width: calc(var(--icon-size) * 0.55);
  height: calc(var(--icon-size) * 0.55);
  object-fit: contain;
}

.tile-text {
  min-width: 0;
  flex: 1;
}

.tile-name {
  display: block;
  font-weight: 560;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-sub {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
}

:root[data-density='compact'] .tile-meta {
  display: none;
}

.tile-meta .sep {
  opacity: 0.4;
}

.badge {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-3);
  font-size: 10.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
}

.badge.warn {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
}

.badge.down {
  background: color-mix(in srgb, var(--down) 18%, transparent);
  color: var(--down);
}

/* --- индикатор статуса --- */

/* Точка сидит в углу иконки — видна и в компактном режиме, где мета-строка скрыта. */
.status-dot {
  position: absolute;
  right: -3px;
  bottom: -3px;
  z-index: 2;
  width: 11px;
  height: 11px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--unknown);
}

.status-dot.up {
  background: var(--up);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 22%, transparent);
}

.status-dot.warn {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent);
}

.status-dot.down {
  background: var(--down);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 24%, transparent);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--down) 8%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .status-dot.down,
  .menu.open .menu-list {
    animation: none;
  }
}

/* --- кнопки на плитке --- */

.tile-actions {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.tile:hover .tile-actions,
.tile:focus-within .tile-actions {
  opacity: 1;
  pointer-events: auto;
}

.tile-actions button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.tile-actions button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.tile-actions button.pinned {
  opacity: 1;
  color: var(--pin);
}

.tile.is-pinned .tile-actions {
  opacity: 1;
  pointer-events: auto;
}

.tile.is-pinned .tile-actions button:not(.pinned) {
  opacity: 0;
  pointer-events: none;
}

.tile:hover.is-pinned .tile-actions button {
  opacity: 1;
  pointer-events: auto;
}

/* --- пустое состояние --- */

.empty {
  padding: 70px 20px;
  text-align: center;
  color: var(--muted);
}

.empty strong {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
  color: var(--text);
}

/* --- модалки --- */

dialog {
  width: min(470px, calc(100vw - 32px));
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(3, 6, 12, 0.62);
  backdrop-filter: blur(4px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 19px 21px 0;
  font-size: 17px;
  font-weight: 620;
}

.dialog-body {
  padding: 16px 21px;
  display: grid;
  gap: 13px;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 21px 19px;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: var(--muted);
  font-size: 12.5px;
}

.field input[type='text'],
.field input[type='url'],
.field input[type='password'],
.field select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
}

.field-row input {
  accent-color: var(--accent);
}

.error {
  color: var(--down);
  font-size: 13px;
  min-height: 18px;
}

/* --- категории в модалке --- */

.cat-list {
  display: grid;
  gap: 7px;
  max-height: 45vh;
  overflow: auto;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid hsl(var(--hue) 70% 58%);
  border-radius: 10px;
}

.cat-row input[type='text'] {
  flex: 1;
  padding: 5px 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  outline: none;
}

.cat-row input[type='text']:focus {
  border-color: var(--border-strong);
  background: var(--surface);
}

.cat-row .cat-icon {
  width: 44px;
  text-align: center;
}

.cat-row .cat-hue {
  width: 74px;
  accent-color: hsl(var(--hue) 70% 58%);
}

.cat-row .cat-count {
  color: var(--muted);
  font-size: 12px;
}

.cat-row button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
}

.cat-row button:hover {
  background: var(--surface-3);
  color: var(--down);
}

/* --- вход --- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: min(360px, 100%);
  padding: 32px 30px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card .brand-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 15px;
  font-size: 17px;
  border-radius: 14px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 19px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13.5px;
}

.login-card form {
  display: grid;
  gap: 12px;
  text-align: left;
}

.login-card .btn-primary {
  justify-content: center;
}

/* --- тосты --- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: grid;
  gap: 8px;
}

.toast {
  padding: 11px 15px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast.error {
  border-color: color-mix(in srgb, var(--down) 45%, transparent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .search-wrap {
    order: 3;
    max-width: none;
    width: 100%;
  }

  .search-hint {
    display: none;
  }

  .stats {
    padding: 16px 16px 0;
    gap: 8px;
  }

  .stat {
    flex: 1;
    min-width: 132px;
    padding: 10px 12px;
  }

  .stat-check {
    width: 100%;
  }

  .board {
    padding: 20px 16px 70px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .tile-actions {
    opacity: 1;
    pointer-events: auto;
  }

  .tile.is-pinned .tile-actions button:not(.pinned) {
    opacity: 1;
    pointer-events: auto;
  }
}
