:root {
  --bg: #0b1120;
  --card: #16213a;
  --card2: #1b2743;
  --line: #26324f;
  --text: #e6edf7;
  --muted: #93a3bd;
  --accent: #3b82f6;
  --accent-h: #2563eb;
  --alert-bg: #3b1d08;
  --alert-fg: #ffce9e;
  --red: #ef4444;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #17233f 0%, var(--bg) 60%);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: #f87171; min-height: 18px; margin-top: 8px; text-align: center; }
.spacer { flex: 1; }

button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover { background: #22314f; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-h); }
button.ghost { background: transparent; }
button.ghost:hover { background: #22314f; }

input, select {
  font: inherit;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0e1830;
  color: var(--text);
  outline: none;
  color-scheme: dark; /* делает иконку календаря и нативные пикеры светлыми на тёмном фоне */
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

/* Свой аккуратный треугольник у select (нативный жмётся к краю) */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2393a3bd' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
/* светлая иконка календаря у datetime-local (на случай, если color-scheme не сработал) */
input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1) brightness(1.6); cursor: pointer; }

/* ---------- Вход ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 340px; display: flex; flex-direction: column; gap: 8px; padding: 32px 28px;
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.login-card .logo { font-size: 40px; text-align: center; }
.login-card h1 { margin: 0; font-size: 24px; text-align: center; }
.login-card > .muted { text-align: center; margin: 0 0 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-card button { margin-top: 18px; padding: 11px; }

/* ---------- Топбар ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  background: rgba(15,23,42,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; }
.pill { background: #0e1830; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; color: var(--muted); font-size: 13px; }

/* ---------- Раскладка: сайдбар + основное ---------- */
.layout { display: flex; align-items: flex-start; }

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  border-right: 1px solid var(--line);
  height: calc(100vh - 57px);
  position: sticky; top: 57px;
  display: flex; flex-direction: column;
  background: rgba(13,20,38,.5);
}
.sidebar-head {
  padding: 16px 18px; font-weight: 700; font-size: 14px;
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
}
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 2px 10px; border-radius: 8px; font-size: 16px; line-height: 1.2;
}
.icon-btn:hover { background: #22314f; color: var(--text); }

/* Свёрнутый вид сайдбара */
.sidebar-collapsed-btn { display: none; }
.sidebar.collapsed { flex-basis: 54px; width: 54px; }
.sidebar.collapsed .sidebar-head,
.sidebar.collapsed .notif-actions,
.sidebar.collapsed .notif-list { display: none; }
.sidebar.collapsed .sidebar-collapsed-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: 100%; height: 100%; padding: 16px 0; background: transparent; border: none;
  color: var(--text); cursor: pointer;
}
.sidebar-collapsed-btn .bell { font-size: 22px; }
.sidebar-collapsed-btn:hover { background: rgba(255,255,255,.04); }
.badge-mini {
  background: var(--red); color: #fff; border-radius: 999px; padding: 1px 7px;
  font-size: 11px; font-weight: 700; animation: pulse 1.8s infinite;
}
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 700; }
.notif-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
button.small { padding: 5px 10px; font-size: 12px; }
.notif-list { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.notif-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }

.notif-card {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px;
  padding: 11px 13px; cursor: pointer; background: var(--card);
  transition: background .12s, transform .05s;
}
.notif-card:hover { background: #1d2a49; }
.notif-card:active { transform: translateY(1px); }
.notif-card.ext { border-left-color: #f59e0b; }
.notif-card.off { border-left-color: var(--red); }
.notif-card .nt { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.notif-card.ext .nt { color: #fcd9a1; }
.notif-card.off .nt { color: #fecaca; }
.notif-card .nd { color: var(--muted); font-size: 12px; }
.notif-card .ntime { color: var(--muted); font-size: 11px; margin-top: 5px; font-variant-numeric: tabular-nums; }

/* ---------- Основное ---------- */
.wrap { flex: 1; min-width: 0; max-width: 1400px; padding: 20px 24px 40px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.controls { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; padding: 16px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; color: var(--muted); }
.device-field { min-width: 340px; flex: 1; }
.device-btn {
  text-align: left; background: #0e1830; border: 1px solid var(--line); font-weight: 600;
  width: 100%; padding: 9px 12px; position: relative;
}
.device-btn::after { content: "▾"; position: absolute; right: 12px; color: var(--muted); }
.device-btn:hover { background: #132043; }

.live { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; padding: 8px 12px; border-radius: 999px; background: #0e1830; border: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 7px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }

.meta { margin: 12px 2px; }

/* ---------- Таблица ---------- */
.table-card { overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--card2); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover td { background: #182545; }
td:nth-child(2), td:nth-child(6) { font-variant-numeric: tabular-nums; }
.dev-name { font-weight: 600; }
.kind-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: #1e2b4a; color: #bcd0f5; }
tr.row-alert td { background: var(--alert-bg); color: var(--alert-fg); }
tr.row-alert:hover td { background: #4a2409; }
tr.row-alert .kind-badge { background: #6a3410; color: #ffd7b0; }

/* Строка «подозрение на отключение» (событие DISCONNECT) — красная */
tr.row-danger td { background: #4a1414; color: #fecaca; font-weight: 600; }
tr.row-danger:hover td { background: #5b1a1a; }
tr.row-danger .kind-badge { background: #7f1d1d; color: #fecaca; }

/* Подсветка события при переходе из уведомления */
tr.row-flash td { animation: flashrow 2s ease-out; }
@keyframes flashrow {
  0% { background: #2563eb; color: #fff; }
  100% { background: inherit; }
}

/* ---------- Модалка выбора устройства ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4,8,18,.7); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px;
}
.modal-card {
  width: max-content; max-width: 90vw; max-height: 90vh; min-width: 380px;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6); overflow: hidden;
}
.modal-head { display: flex; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.modal-head input { flex: 1; }
.modal-table-wrap { overflow: auto; } /* скролл по обеим осям, когда упёрлись в 90% */
.modal-table-wrap table { width: 100%; }
.modal-table-wrap tbody tr { cursor: pointer; }
.modal-table-wrap tbody tr:hover td { background: #1d2a49; }
.st-on { color: #4ade80; }
.st-off { color: #fca5a5; font-weight: 600; }

@media (max-width: 900px) {
  .sidebar { position: static; height: auto; flex-basis: auto; width: 100%; border-right: none; border-bottom: 1px solid var(--line); }
  .layout { flex-direction: column; }
  .notif-list { max-height: 240px; }
}
