/* =====================================================================
   AB-ALERT PANEL — стиль у дусі asgardbud.com.ua
   (Inter, #007AFF / #5856D6, світла й темна тема, м’які анімації)
   ===================================================================== */

/* ------------------------------------------------------------ ролі */
/* Оператор бачить стан і може вручну ввімкнути тривогу/відбій,
   але керувальні елементи від нього приховані (сервер це теж перевіряє). */
body[data-role="operator"] .admin-only { display: none !important; }

/* ---------------------------------------------------------------- аудіо */
.audio-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
#clip-wave {
  width: 100%; height: 90px; display: block; border-radius: var(--radius);
  background: var(--log-bg); border: 1px solid var(--border-soft);
}
.clip-range { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.clip-range .field { flex: 1 1 160px; }
.algo-row .audio-clip { flex: 1 1 200px; min-width: 160px; }
.clip-used { color: var(--gray); font-size: 12px; }

/* прослухати налаштовану послідовність на самому пристрої */
.ev-play { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.ev-play .icon-btn { width: 32px; height: 32px; }
.ev-play .icon-btn svg { width: 15px; height: 15px; }
body[data-role="operator"] .ev-play { display: none; }

/* дві бібліотеки: сервер і пристрій */
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.lib-col { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.lib-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.lib-head b { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.lib-head svg { width: 15px; height: 15px; opacity: .7; }
.lib-list { max-height: 380px; overflow-y: auto; }
.lib-empty { padding: 20px 14px; color: var(--gray); font-size: 13px; text-align: center; }
.lib-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.lib-item:last-child { border-bottom: none; }
.lib-item:hover { background: var(--bg-soft); }
.lib-item .nm { flex: 1; min-width: 0; }
.lib-item .nm b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .nm span { font-size: 11px; color: var(--gray); }
.lib-item .acts { display: flex; gap: 4px; flex-shrink: 0; }
.lib-item .icon-btn { width: 28px; height: 28px; }
.lib-item .icon-btn svg { width: 14px; height: 14px; }
.kind-pill {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
}
.kind-pill.clip { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }
.kind-pill.preamble { color: var(--secondary); background: color-mix(in srgb, var(--secondary) 14%, transparent); }
.lib-item.playing { background: color-mix(in srgb, var(--primary) 8%, transparent); }

@media (max-width: 860px) { .lib-grid { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .clip-range .field { flex: 1 1 100%; } }

:root {
  --primary: #007AFF;
  --primary-rgb: 0, 122, 255;
  --secondary: #5856D6;
  --grad: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --surface-3: #eef0f3;
  --sidebar: #ffffff;
  --text: #333333;
  --text-strong: #111111;
  --text-2: #666666;
  --text-3: #8e8e93;
  --border: #e1e1e1;
  --border-soft: #ececec;
  --shadow: 0 2px 10px rgba(0, 0, 0, .06);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .12);
  --focus: 0 0 0 4px rgba(0, 122, 255, .18);

  --red: #FF3B30;    --red-rgb: 255, 59, 48;
  --yellow: #FFB800; --yellow-rgb: 255, 184, 0;
  --green: #34C759;  --green-rgb: 52, 199, 89;
  --orange: #FF9500;
  --gray: #8E8E93;

  --radius: 16px;
  --radius-sm: 10px;
  --btn-radius: 8px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --t: all .3s ease;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --log-bg: #0f1115;
  --log-text: #d6d9df;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface-2: #2a2a2a;
  --surface-3: #313131;
  --sidebar: #000000;
  --text: #ffffff;
  --text-strong: #ffffff;
  --text-2: #cccccc;
  --text-3: #8e8e93;
  --border: #333333;
  --border-soft: #2e2e2e;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .6);
  --log-bg: #0b0b0c;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  transition: background-color .3s ease, color .3s ease;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: rgba(var(--primary-rgb), .22); }

.ic {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-lg { width: 24px; height: 24px; }
.ic-xl { width: 34px; height: 34px; }

/* ----------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: 264px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 22px 16px 16px;
  z-index: 50;
  transition: transform .35s var(--ease), background-color .3s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 22px; color: var(--text); }
.brand-logo { height: 42px; width: auto; transition: var(--t); }
[data-theme="dark"] .brand-logo, [data-theme="dark"] .login-logo { filter: invert(1); }
.brand:hover .brand-logo { transform: rotate(-6deg) scale(1.05); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; }
.brand-sub { font-size: .78rem; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); padding: 16px 12px 6px; font-weight: 600;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  transition: background-color .25s ease, color .25s ease, transform .25s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--primary); transform: translateX(2px); }
.nav-item.active { background: rgba(var(--primary-rgb), .1); color: var(--primary); }
.nav-item.active::before {
  content: ""; position: absolute; left: -16px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--grad);
  animation: grow-y .35s var(--ease);
}
.nav-badge {
  margin-left: auto; min-width: 24px; padding: 1px 8px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; text-align: center;
  background: var(--surface-3); color: var(--text-2);
}
.nav-badge-green { background: rgba(var(--green-rgb), .15); color: var(--green); }
.nav-sub { display: flex; flex-direction: column; margin: 2px 0 6px 22px; border-left: 1px solid var(--border); }
.nav-subitem {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; margin-left: 8px; border-radius: 8px;
  font-size: .88rem; color: var(--text-2);
  transition: var(--t);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-subitem:hover { color: var(--primary); background: var(--surface-2); }
.nav-subitem.active { color: var(--primary); font-weight: 600; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--grad); color: #fff; font-weight: 700;
  display: grid; place-items: center; flex: none;
}
.user-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ver { font-size: .72rem; color: var(--text-3); padding: 0 6px; }

/* theme switch (як на сайті) */
.theme-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 0 4px; user-select: none; }
.theme-switch input { display: none; }
.theme-track {
  position: relative; width: 60px; height: 32px; border-radius: 34px;
  background: #ccc; transition: background-color .4s ease; flex: none;
}
.theme-thumb {
  position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; display: grid; place-items: center;
  transition: transform .4s var(--ease);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.theme-thumb .ic { width: 14px; height: 14px; position: absolute; transition: opacity .3s, transform .4s; color: #f5a623; }
.theme-thumb .ic-moon { opacity: 0; transform: rotate(-90deg); color: var(--secondary); }
.theme-switch input:checked + .theme-track { background: var(--primary); }
.theme-switch input:checked + .theme-track .theme-thumb { transform: translateX(28px); }
.theme-switch input:checked + .theme-track .ic-sun { opacity: 0; transform: rotate(90deg); }
.theme-switch input:checked + .theme-track .ic-moon { opacity: 1; transform: rotate(0); }
.theme-label { font-size: .88rem; color: var(--text-2); }

.main { flex: 1; margin-left: 264px; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 32px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
.crumb { color: var(--text-3); font-weight: 500; transition: color .2s; white-space: nowrap; }
a.crumb:hover { color: var(--primary); }
.crumb-sep { color: var(--text-3); display: flex; }
.crumb-sep .ic { width: 14px; height: 14px; }
.crumb-current { color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.clock { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 500; font-size: .9rem; }
.icon-btn.burger { display: none; }
.alert-pills { display: flex; gap: 8px; }
.alert-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; border-radius: 30px;
  font-size: .82rem; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); white-space: nowrap;
  transition: var(--t);
  animation: fade-in .4s ease;
}
.alert-pill .pill-name { color: var(--text-2); font-weight: 500; }
.alert-pill:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.content { padding: 28px 32px 60px; max-width: 1480px; width: 100%; }

/* ---------------------------------------------------------- headings */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; color: var(--text-strong); line-height: 1.15; }
.page-head p { color: var(--text-2); margin-top: 6px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.gradient-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.section-title { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; font-weight: 700; color: var(--text-strong); }
.section-title .ic { color: var(--primary); }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- cards */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: transform .3s ease, box-shadow .3s ease, background-color .3s ease, border-color .3s ease;
  min-width: 0;
}
.card-hover:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-soft); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px;
  border-radius: var(--btn-radius);
  font-weight: 600; font-size: .92rem;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--t);
  white-space: nowrap;
  text-decoration: none;
  background: none;
  position: relative;
  overflow: hidden;
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--secondary); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(88, 86, 214, .3); }
.btn-secondary { border-color: var(--primary); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: var(--primary); color: #fff; transform: translateY(-2px); }
.btn-ghost { border-color: var(--border); color: var(--text); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #d92c22; transform: translateY(-2px); box-shadow: 0 8px 20px rgba(var(--red-rgb), .3); }
.btn-sm { padding: 7px 13px; font-size: .84rem; }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; }
.btn.loading { pointer-events: none; opacity: .75; }
/* хвиля при кліку */
.btn .ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: rgba(255, 255, 255, .45); animation: ripple .6s ease-out; pointer-events: none;
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid transparent; background: none; cursor: pointer; color: var(--text-2);
  transition: var(--t);
}
.icon-btn:hover { background: var(--surface-2); color: var(--primary); border-color: var(--border); }

/* ------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.hint { font-size: .78rem; color: var(--text-3); }
.input, select.input, textarea.input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--btn-radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .2s, box-shadow .2s, background-color .3s;
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: var(--focus); }
.input-sm { padding: 7px 10px; font-size: .88rem; }
select.input {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-section { font-weight: 700; margin: 8px 0 -4px; grid-column: 1 / -1; color: var(--text-strong); display: flex; align-items: center; gap: 8px; }
.form-section .ic { color: var(--primary); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.search-box { position: relative; }
.search-box .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; }
.search-box .input { padding-left: 36px; }

/* segmented control */
.seg {
  position: relative; display: inline-flex; padding: 4px; gap: 2px;
  background: var(--surface-3); border-radius: 11px;
}
.seg button {
  position: relative; z-index: 1;
  border: none; background: none; cursor: pointer;
  padding: 7px 14px; border-radius: 8px;
  font-weight: 600; font-size: .85rem; color: var(--text-2);
  transition: color .25s;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button.on { color: var(--text-strong); }
.seg .seg-thumb {
  position: absolute; top: 4px; bottom: 4px; left: 0;
  background: var(--surface); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: transform .35s var(--ease), width .35s var(--ease);
}

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { display: none; }
.switch .track { width: 46px; height: 26px; border-radius: 26px; background: var(--border); position: relative; transition: background-color .3s; flex: none; }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: transform .35s var(--ease);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); }

/* -------------------------------------------------------------- tabs */
.tabs { position: relative; display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 16px; border: none; background: none; cursor: pointer;
  color: var(--text-2); font-weight: 600; white-space: nowrap;
  transition: color .25s;
}
.tab:hover { color: var(--primary); }
.tab.on { color: var(--primary); }
.tab-ink {
  position: absolute; bottom: -1px; left: 0; height: 3px; border-radius: 3px 3px 0 0;
  background: var(--grad);
  transition: transform .4s var(--ease), width .4s var(--ease);
}
.pane { display: none; }
.pane.on { display: block; animation: pane-in .45s var(--ease); }

/* ------------------------------------------------------ status/badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 20px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge .ic { width: 13px; height: 13px; }
.badge-green { background: rgba(var(--green-rgb), .14); color: #1f9d45; }
.badge-red { background: rgba(var(--red-rgb), .13); color: var(--red); }
.badge-yellow { background: rgba(var(--yellow-rgb), .18); color: #b07d00; }
.badge-blue { background: rgba(var(--primary-rgb), .12); color: var(--primary); }
.badge-violet { background: rgba(88, 86, 214, .14); color: var(--secondary); }
[data-theme="dark"] .badge-green { color: #4cd964; }
[data-theme="dark"] .badge-yellow { color: #ffd23f; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); flex: none; position: relative; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.pulse::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: inherit; animation: pulse-ring 1.8s ease-out infinite;
}

/* ------------------------------------------------------- stat tiles */
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--text-2); font-weight: 500; }
.stat-label .ic { width: 15px; height: 15px; color: var(--primary); }
.stat-value { font-size: 1.55rem; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.2; }
.stat-value small { font-size: .9rem; font-weight: 500; color: var(--text-2); margin-left: 3px; }
.stat-sub { font-size: .8rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; width: 0; border-radius: 6px; background: var(--grad); transition: width .9s var(--ease), background-color .3s; }
.meter.warn > span { background: var(--orange); }
.meter.crit > span { background: var(--red); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; font-size: .9rem; }
.kv dt { color: var(--text-2); }
.kv dd { color: var(--text-strong); font-weight: 500; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tr { transition: background-color .2s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }

/* -------------------------------------------------------------- logs */
.logbox {
  background: var(--log-bg); color: var(--log-text);
  border-radius: 12px;
  font-family: var(--mono); font-size: .78rem; line-height: 1.6;
  height: 520px; overflow: auto; padding: 14px 16px;
  border: 1px solid #1d2027;
}
.logbox .ln { white-space: pre-wrap; word-break: break-word; padding: 0 4px; border-radius: 4px; }
.logbox .ln.new { animation: log-in .6s ease; }
.logbox .ln:hover { background: rgba(255,255,255,.04); }
.logbox .ts { color: #6c7486; }
.logbox .lv-INFO { color: #5ac8fa; }
.logbox .lv-WARNING, .logbox .lv-WARN { color: #ffcc00; }
.logbox .lv-ERROR, .logbox .lv-CRITICAL { color: #ff6b61; }
.logbox .hl-state { color: #fff; background: rgba(255, 59, 48, .22); border-radius: 4px; padding: 0 3px; }
.logbox .hl-ok { color: #4cd964; }
.logbox .hl-cfg { color: #4cd964; }
.logbox .hl-dev { color: #bf9dff; }
.logbox .empty { color: #6c7486; text-align: center; padding: 40px 0; }
.logbox mark { background: rgba(255, 204, 0, .35); color: inherit; border-radius: 3px; }
.log-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.log-toolbar .grow { flex: 1; min-width: 180px; }

/* ---------------------------------------------------------- terminal */
.term-wrap {
  background: #0b0b0c; border-radius: 12px; padding: 10px; height: 560px;
  border: 1px solid #1d2027; position: relative; overflow: hidden;
}
.term-wrap .xterm { height: 100%; }
.term-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: #cfd3da; background: rgba(11, 11, 12, .85); backdrop-filter: blur(3px);
  transition: opacity .3s; z-index: 5;
}
.term-overlay.hidden { opacity: 0; pointer-events: none; }
.term-overlay .ic-xl { color: var(--primary); margin-bottom: 10px; }

/* --------------------------------------------------------------- map */
.map { height: 460px; border-radius: 12px; overflow: hidden; background: var(--surface-2); position: relative; z-index: 0; }
.map-tall { height: 560px; }
.map-fallback { display: grid; place-items: center; height: 100%; color: var(--text-3); text-align: center; padding: 20px; }
.leaflet-container { font-family: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--text-3) !important; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.map.picking { cursor: crosshair; outline: 3px solid rgba(var(--primary-rgb), .5); outline-offset: -3px; }
.map.picking .leaflet-container { cursor: crosshair; }

.mk { position: relative; width: 22px; height: 22px; }
.mk-core {
  position: absolute; inset: 3px; border-radius: 50%;
  background: var(--gray); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  transition: background-color .3s;
}
.mk-ring { position: absolute; inset: 0; border-radius: 50%; }
.mk.CLEAR .mk-core { background: var(--green); }
.mk.YELLOW .mk-core { background: var(--yellow); }
.mk.RED .mk-core { background: var(--red); }
.mk.offline .mk-core { background: var(--gray); }
.mk.RED .mk-ring { background: rgba(var(--red-rgb), .5); animation: pulse-ring 1.4s ease-out infinite; }
.mk.YELLOW .mk-ring { background: rgba(var(--yellow-rgb), .5); animation: pulse-ring 2.2s ease-out infinite; }
.mk-label {
  position: absolute; left: 50%; top: 24px; transform: translateX(-50%);
  white-space: nowrap; font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.popup-title { font-weight: 700; margin-bottom: 4px; }

/* ------------------------------------------------------ server cards */
.server-card { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 16px; color: inherit; }
.server-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--grad);
  transform: scaleX(0); transform-origin: left; transition: transform .5s var(--ease);
}
.server-card:hover::before { transform: scaleX(1); }
.server-card-head { display: flex; align-items: center; gap: 14px; }
.server-ico {
  width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(var(--primary-rgb), .1); color: var(--primary); flex: none;
  transition: transform .4s var(--ease);
}
.server-card:hover .server-ico { transform: rotate(-8deg) scale(1.06); }
.server-card h3 { font-size: 1.15rem; color: var(--text-strong); }
.add-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--border); background: transparent; box-shadow: none;
  color: var(--text-2); min-height: 200px;
}
.add-card:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-4px); }

/* --------------------------------------------------- alert indicator */
.alarm {
  position: relative; display: flex; align-items: center; gap: 22px;
  padding: 22px; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2);
  transition: background-color .5s ease;
}
.alarm-orb { position: relative; width: 86px; height: 86px; flex: none; }
.alarm-orb .core {
  position: absolute; inset: 14px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: var(--gray);
  transition: background-color .5s ease, box-shadow .5s ease;
}
.alarm-orb .core .ic { width: 28px; height: 28px; }
.alarm-orb .ring { position: absolute; inset: 0; border-radius: 50%; opacity: 0; }
.alarm-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; color: var(--text-strong); line-height: 1.15; }
.alarm-sub { color: var(--text-2); margin-top: 4px; font-size: .9rem; }
.alarm.CLEAR { background: linear-gradient(135deg, rgba(var(--green-rgb), .12), rgba(var(--green-rgb), .03)); }
.alarm.CLEAR .core { background: var(--green); box-shadow: 0 0 0 8px rgba(var(--green-rgb), .15); }
.alarm.YELLOW { background: linear-gradient(135deg, rgba(var(--yellow-rgb), .2), rgba(var(--yellow-rgb), .04)); }
.alarm.YELLOW .core { background: var(--yellow); box-shadow: 0 0 30px rgba(var(--yellow-rgb), .55); animation: breathe 2.4s ease-in-out infinite; }
.alarm.YELLOW .ring { background: rgba(var(--yellow-rgb), .35); animation: pulse-ring 2.4s ease-out infinite; }
.alarm.RED { background: linear-gradient(135deg, rgba(var(--red-rgb), .2), rgba(var(--red-rgb), .04)); }
.alarm.RED .core { background: var(--red); box-shadow: 0 0 36px rgba(var(--red-rgb), .6); animation: breathe 1.2s ease-in-out infinite; }
.alarm.RED .ring { background: rgba(var(--red-rgb), .35); animation: pulse-ring 1.4s ease-out infinite; }
.alarm.RED .ring.r2, .alarm.YELLOW .ring.r2 { animation-delay: .6s; }
.alarm.OFFLINE .core { background: var(--gray); }

/* ------------------------------------------------ force alarm buttons */
.force-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.force-btn {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 16px; border-radius: 14px; cursor: pointer; text-align: left;
  border: 2px solid transparent; color: #fff; font-weight: 700;
  transition: transform .3s ease, box-shadow .3s ease, filter .3s;
}
.force-btn .ic { width: 26px; height: 26px; }
.force-btn small { font-weight: 500; opacity: .85; font-size: .78rem; }
.force-btn:hover { transform: translateY(-3px); }
.force-btn:active { transform: translateY(0) scale(.98); }
.force-btn.red { background: linear-gradient(135deg, #ff453a, #d70015); box-shadow: 0 8px 22px rgba(var(--red-rgb), .28); }
.force-btn.yellow { background: linear-gradient(135deg, #ffc93c, #ff9f0a); color: #3b2a00; box-shadow: 0 8px 22px rgba(var(--yellow-rgb), .3); }
.force-btn.green { background: linear-gradient(135deg, #34c759, #248a3d); box-shadow: 0 8px 22px rgba(var(--green-rgb), .28); }
.force-btn.active { border-color: var(--text-strong); }
.force-btn.active::after {
  content: "АКТИВНО"; position: absolute; top: 12px; right: 12px;
  font-size: .62rem; letter-spacing: .08em; padding: 2px 7px; border-radius: 10px;
  background: rgba(255,255,255,.3);
}
.force-btn:disabled { filter: grayscale(.8); opacity: .55; cursor: not-allowed; transform: none; }
.forced-banner {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  padding: 12px 14px; border-radius: 12px;
  background: rgba(var(--primary-rgb), .08); border: 1px solid rgba(var(--primary-rgb), .25);
  animation: fade-in .4s ease;
}
.forced-banner .grow { flex: 1; font-size: .88rem; }

/* ------------------------------------------------------------ relays */
.relays { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.relay {
  position: relative; border-radius: 14px; padding: 14px 14px 12px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 10px;
  transition: var(--t); user-select: none; min-width: 0;
}
.relay-top { display: flex; align-items: center; justify-content: space-between; }
.relay-num { font-weight: 800; font-size: 1.05rem; color: var(--text-strong); }
.lamp {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-3); border: 2px solid var(--border);
  transition: background-color .15s, box-shadow .15s, border-color .15s;
}
.relay.on .lamp { background: #ffcc00; border-color: #ffdf5e; box-shadow: 0 0 14px rgba(255, 204, 0, .9); }
.relay.on { border-color: rgba(255, 204, 0, .55); }
.relay-name { font-size: .78rem; color: var(--text-2); line-height: 1.25; min-height: 2.5em; overflow-wrap: anywhere; }
.relay-state { font-size: .72rem; font-weight: 700; letter-spacing: .05em; color: var(--text-3); }
.relay.on .relay-state { color: #c79a00; }
.relays.manual .relay { cursor: pointer; }
.relays.manual .relay:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary); }
.relays.manual .relay:active { transform: scale(.97); }
.relay .test-btn { position: absolute; right: 8px; bottom: 8px; opacity: 0; transition: opacity .2s; width: 28px; height: 28px; }
.relay .test-btn .ic { width: 14px; height: 14px; }
.relays:not(.manual) .relay:hover .test-btn { opacity: 1; }
.relay.pending { animation: pending 1s ease-in-out infinite; }
.manual-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  background: var(--surface-2);
  transition: background-color .4s;
}
.manual-bar.manual { background: rgba(255, 149, 0, .12); }

/* ------------------------------------------------ algorithm editor */
.algo { display: flex; flex-direction: column; gap: 12px; }
.algo-row {
  display: grid; grid-template-columns: 210px minmax(0, 1.1fr) 200px minmax(0, 1.2fr) 150px;
  gap: 16px; align-items: center;
  padding: 14px 16px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  transition: border-color .3s, box-shadow .3s, transform .3s;
}
.algo-row:hover { border-color: rgba(var(--primary-rgb), .35); }
.algo-row.changed { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255, 149, 0, .12); }
.algo-ev { display: flex; align-items: center; gap: 12px; min-width: 0; }
.algo-ev .ev-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none; color: #fff; }
.algo-ev b { display: block; color: var(--text-strong); }
.algo-ev span { font-size: .76rem; color: var(--text-3); line-height: 1.3; display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 700; font-size: .85rem; color: var(--text-2);
  transition: all .2s ease;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; transform: scale(1.04); }
.algo-params { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.algo-params .field { width: 112px; transition: opacity .3s, transform .3s; }
.algo-params .field.hide { display: none; }
.algo-params .field label { font-size: .7rem; }
.algo-params .none { font-size: .8rem; color: var(--text-3); }
/* допоміжне реле тривоги: вибір рівнів, на які воно реагує */
.algo-params .field[data-p="triggers"] { width: auto; }
.trig { display: flex; gap: 10px; padding: 4px 0 2px; }
.trig-op { display: flex; align-items: center; gap: 4px; font-size: .78rem; white-space: nowrap; cursor: pointer; }
.trig-op input { accent-color: var(--primary); margin: 0; cursor: pointer; }
.wave { height: 34px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border-soft); overflow: hidden; position: relative; }
.wave svg { width: 100%; height: 100%; display: block; }
.wave .wave-line { fill: none; stroke: var(--primary); stroke-width: 2; }
.wave .wave-fill { fill: rgba(var(--primary-rgb), .12); stroke: none; }
.wave .playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--secondary); opacity: .6; animation: playhead 4s linear infinite; }
.algo-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 24px; margin-top: 6px; padding: 16px; border-radius: 14px; background: var(--surface-2); }
.apply-state { display: flex; align-items: center; gap: 8px; font-size: .88rem; }

/* --------------------------------------------------- device list */
.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.dev-card { display: flex; flex-direction: column; gap: 12px; cursor: pointer; color: inherit; position: relative; overflow: hidden; }
.dev-card .state-stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--gray); transition: background-color .4s; }
.dev-card.CLEAR .state-stripe { background: var(--green); }
.dev-card.YELLOW .state-stripe { background: var(--yellow); }
.dev-card.RED .state-stripe { background: var(--red); animation: blink-bg 1.2s ease-in-out infinite; }
.dev-card.offline .state-stripe { background: var(--gray); animation: none; }
.dev-card h4 { font-size: 1rem; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 22px 0 16px; }
.counter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.counter { display: flex; align-items: center; gap: 14px; }
.counter .c-ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; flex: none; }
.c-blue { background: rgba(var(--primary-rgb), .1); color: var(--primary); }
.c-green { background: rgba(var(--green-rgb), .12); color: var(--green); }
.c-red { background: rgba(var(--red-rgb), .12); color: var(--red); }
.c-yellow { background: rgba(var(--yellow-rgb), .16); color: #d19a00; }
.c-violet { background: rgba(88, 86, 214, .12); color: var(--secondary); }

/* ------------------------------------------------------ cmd history */
.cmd-list { display: flex; flex-direction: column; gap: 6px; max-height: 250px; overflow: auto; }
.cmd {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); font-size: .84rem; animation: fade-in .35s ease;
}
.cmd .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------ misc widgets */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-2); }
.empty-state .ic { width: 46px; height: 46px; color: var(--text-3); margin-bottom: 12px; }
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: 12px; font-size: .9rem;
  background: rgba(var(--primary-rgb), .07); border: 1px solid rgba(var(--primary-rgb), .2);
  margin-bottom: 18px; animation: fade-in .4s ease;
}
.notice .ic { color: var(--primary); margin-top: 2px; }
.notice.warn { background: rgba(255, 149, 0, .08); border-color: rgba(255, 149, 0, .3); }
.notice.warn .ic { color: var(--orange); }
.notice.err { background: rgba(var(--red-rgb), .07); border-color: rgba(var(--red-rgb), .25); }
.notice.err .ic { color: var(--red); }
.notice code { font-family: var(--mono); font-size: .85em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

.skeleton {
  border-radius: 8px; min-height: 1em;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%; display: inline-block;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; flex: none;
}
.loadbar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 200;
  background: var(--grad); opacity: 0;
  transition: width .4s ease, opacity .4s ease;
}
.loadbar.on { opacity: 1; width: 70%; transition: width 8s cubic-bezier(.1,.6,.2,1), opacity .2s; }
.loadbar.done { opacity: 0; width: 100%; transition: width .25s ease, opacity .4s .25s; }

/* toasts */
.toasts { position: fixed; right: 22px; bottom: 22px; z-index: 300; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 12px;
  min-width: 260px; max-width: 420px;
  padding: 13px 16px; border-radius: 12px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  animation: toast-in .45s var(--ease);
  font-size: .9rem;
}
.toast.out { animation: toast-out .35s ease forwards; }
.toast .ic { flex: none; }
.toast.ok .ic { color: var(--green); }
.toast.error .ic { color: var(--red); }
.toast.info .ic { color: var(--primary); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(0, 0, 0, .45); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 440px; background: var(--surface); border-radius: 20px;
  padding: 28px; box-shadow: var(--shadow-lg); text-align: center;
  transform: translateY(20px) scale(.95); transition: transform .4s var(--ease);
}
.modal-backdrop.open .modal { transform: none; }
.modal h3 { font-size: 1.25rem; margin: 10px 0 6px; color: var(--text-strong); }
.modal p { color: var(--text-2); font-size: .95rem; }
.modal-icon { width: 58px; height: 58px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; background: rgba(var(--primary-rgb), .1); color: var(--primary); }
.modal-icon.danger { background: rgba(var(--red-rgb), .12); color: var(--red); }
.modal-icon .ic { width: 28px; height: 28px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; }
.modal-actions .btn { min-width: 130px; }

/* ------------------------------------------------------------ login */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, #ffffff 0%, #e9e9e9 45%, #9a9a9a 100%);
  position: relative; overflow: hidden;
}
[data-theme="dark"] .login-page { background: linear-gradient(160deg, #2a2a2a 0%, #141414 50%, #000 100%); }
.login-page::before, .login-page::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(80px); opacity: .35; pointer-events: none;
}
.login-page::before { width: 480px; height: 480px; background: #007AFF; top: -160px; right: -120px; animation: float 14s ease-in-out infinite; }
.login-page::after { width: 420px; height: 420px; background: #5856D6; bottom: -160px; left: -120px; animation: float 16s ease-in-out infinite reverse; }
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 24px; padding: 40px 36px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border-soft);
  animation: rise .8s var(--ease);
}
.login-logo { display: block; height: 120px; margin: 0 auto 14px; animation: logo-in 1s var(--ease); }
.login-card h1 { text-align: center; font-size: 1.7rem; font-weight: 800; color: var(--text-strong); letter-spacing: -.02em; }
.login-card .tag { text-align: center; color: var(--text-2); margin: 4px 0 26px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; }
.login-err { background: rgba(var(--red-rgb), .1); color: var(--red); padding: 10px 14px; border-radius: 10px; font-size: .9rem; animation: shake .45s ease; }
.login-theme { position: fixed; top: 20px; right: 20px; z-index: 5; }
.login-foot { text-align: center; margin-top: 22px; font-size: .78rem; color: var(--text-3); }

/* --------------------------------------------------------- animation */
[data-anim] { opacity: 0; transform: translateY(18px); transition: opacity .7s var(--ease), transform .7s var(--ease); transition-delay: var(--d, 0s); }
[data-anim="fade"] { transform: none; }
[data-anim="zoom"] { transform: scale(.96); }
[data-anim].in { opacity: 1; transform: none; }
.page-enter { animation: page-in .5s var(--ease); }
.value-flash { animation: value-flash .8s ease; }

@keyframes page-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pane-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes logo-in { from { opacity: 0; transform: scale(.8) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(40px, 30px); } }
@keyframes pulse-ring { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(2.6); opacity: 0; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(40px); } }
@keyframes ripple { to { transform: scale(4); opacity: 0; } }
@keyframes grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes log-in { from { background: rgba(0, 122, 255, .25); } to { background: transparent; } }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes value-flash { from { color: var(--primary); } }
@keyframes pending { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes blink-bg { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes playhead { from { left: 0; } to { left: 100%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  [data-anim] { opacity: 1; transform: none; }
}

/* -------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .algo-row { grid-template-columns: 200px minmax(0, 1fr) 190px; }
  .algo-row .wave { grid-column: 2 / -1; }
  .algo-row .algo-params { grid-column: 1 / -1; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .counter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .algo-options { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .3s; }
  .sidebar.open + .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .icon-btn.burger { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px 50px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .relays { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .algo-row { grid-template-columns: 1fr; }
  .algo-row .wave, .algo-row .algo-params { grid-column: auto; }
  .force-grid { grid-template-columns: 1fr; }
  .alert-pills .alert-pill .pill-name, .clock { display: none; }
  .page-head h1 { font-size: 1.55rem; }
  .logbox { height: 420px; }
  .term-wrap { height: 460px; }
  .map-tall { height: 420px; }
}
@media (max-width: 560px) {
  .grid-4, .counter-row, .algo-options { grid-template-columns: 1fr; }
  .alarm { flex-direction: column; text-align: center; }
  .alert-pill span:not(.dot) { display: none; }
  .alert-pill { padding: 9px; }
  .page-actions .btn { flex: 1 1 auto; white-space: normal; text-align: center; }
}

/* ==================================================================
   Ролі та демонстраційний режим
   ================================================================== */
.user-role { display: block; font-size: .68rem; font-weight: 500; color: var(--text-3); text-transform: lowercase; }
.badge.role-admin, .user-role.role-admin { color: var(--primary); }
.badge.role-admin { background: rgba(var(--primary-rgb), .12); }
.badge.role-engineer, .user-role.role-engineer { color: var(--secondary); }
.badge.role-engineer { background: rgba(88, 86, 214, .14); }
.badge.role-operator, .user-role.role-operator { color: #b07d00; }
.badge.role-operator { background: rgba(var(--yellow-rgb), .18); }
.badge.role-demo, .user-role.role-demo { color: #1f9d45; }
.badge.role-demo { background: rgba(var(--green-rgb), .14); }

.demo-banner {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; margin-bottom: 18px; border-radius: 12px;
  background: rgba(var(--green-rgb), .10);
  border: 1px solid rgba(var(--green-rgb), .28);
  color: var(--text-1); font-size: .88rem; line-height: 1.45;
}
.demo-banner .ic { width: 20px; height: 20px; flex: none; color: #1f9d45; margin-top: 1px; }

/* елементи, недоступні ролі: видно, але не діють */
.no-perm { opacity: .5; cursor: not-allowed; }

/* ==================================================================
   Видача пристроїв користувачу
   ================================================================== */
.roles-help { padding: 4px 20px 10px; display: flex; flex-direction: column; gap: 7px; font-size: .82rem; color: var(--text-2); line-height: 1.45; }
.roles-help .badge { margin-right: 6px; }
.grant-row > td { background: var(--surface); padding: 16px 20px !important; }
.grants-head { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.grants-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 18px; }
.grants-server { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 600;
                 color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; margin: 10px 0 2px; }
.grants-server .ic { width: 14px; height: 14px; }
.grant-op { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; min-width: 0; }
.grant-op:hover { background: var(--surface-2); }
.grant-op input { accent-color: var(--primary); cursor: pointer; flex: none; }
.grant-op .grant-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grant-op .small { white-space: nowrap; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-grey { background: var(--gray); }
.grants-foot { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ==================================================================
   Джерела даних про тривогу (основне / резервне)
   ================================================================== */
.sources { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.sources-head {
  display: flex; align-items: center; gap: 7px; font-size: .74rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px;
}
.sources-head .ic { width: 14px; height: 14px; }
.src-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding: 5px 0; font-size: .87rem; }
.src-row b { font-weight: 600; }
.src-role {
  font-size: .68rem; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3);
  background: var(--surface-3); padding: 1px 7px; border-radius: 4px;
}
.src-live {
  font-size: .68rem; letter-spacing: .05em; text-transform: uppercase; font-weight: 700;
  color: #1f9d45; background: rgba(var(--green-rgb), .14); padding: 1px 7px; border-radius: 4px;
}
.src-note { color: var(--text-3); font-size: .82rem; margin-left: auto; text-align: right; }
.src-warn { margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: .84rem; line-height: 1.45; }
.src-warn.warn { background: rgba(var(--yellow-rgb), .14); color: #8a6100; }
.src-warn.note { background: rgba(var(--primary-rgb), .09); color: var(--text-2); }
[data-theme="dark"] .src-warn.warn { color: #e0b055; }
@media (max-width: 560px) { .src-note { margin-left: 0; width: 100%; text-align: left; } }
