/* Device Inspector (window.infraOpenDevice) — правый drawer сетевого
 * устройства (Network Intelligence Phase 2).
 *
 * Отдельный модуль со своими классами .nid-*: панель 450px, overlay без blur,
 * sticky header + вкладки + скролл только контента, resize-handle 400–700px
 * (localStorage), transform .17s ease-out. z-index выше Machine Inspector
 * (1400) и Network Inspector (1500) — 1600/1601.
 *
 * Цвет — семантика: --nid-ok/warn/bad/info/muted выводятся из общих переменных
 * кабинета (cabinet.css). Стили cabinet-infra.css/cabinet-network.css не
 * трогаем.
 */

/* ─── overlay / drawer ────────────────────────────────────────────────── */
.nid-overlay {
    --nid-overlay-bg: rgba(0, 0, 0, .18);
    position: fixed;
    inset: 0;
    z-index: 1600;
    background: var(--nid-overlay-bg);
    opacity: 0;
    visibility: hidden;
    transition: opacity .16s ease, visibility .16s ease;
}
.nid-overlay.nid-open { opacity: 1; visibility: visible; }
body.light-theme .nid-overlay { --nid-overlay-bg: rgba(16, 24, 32, .16); }

.nid-drawer {
    --nid-ok: var(--accent);
    --nid-warn: #C99A2E;
    --nid-bad: var(--danger);
    --nid-info: #4C8DFF;
    --nid-shadow: rgba(0, 0, 0, .28);

    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: var(--nid-w, 450px);
    min-width: min(400px, 100vw);
    max-width: min(700px, 100vw);
    z-index: 1601;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    color: var(--text);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px var(--nid-shadow);
    transform: translateX(102%);
    transition: transform .17s ease-out;
    font-size: 12.5px;
    line-height: 1.3;
}
body.light-theme .nid-drawer {
    --nid-warn: #9A6700;
    --nid-info: #0969DA;
    --nid-shadow: rgba(16, 24, 32, .12);
}
.nid-drawer.nid-open { transform: translateX(0); }

/* Resize handle на левой границе: 400 → 700px, значение в localStorage. */
.nid-resize {
    position: absolute;
    top: 0;
    left: -3px;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    z-index: 3;
    touch-action: none;
}
.nid-resize::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 3px;
    width: 2px;
    height: 34px;
    margin-top: -17px;
    border-radius: 1px;
    background: transparent;
    transition: background .12s ease;
}
.nid-resize:hover::after, .nid-resize.nid-dragging::after { background: var(--border2); }
body.nid-resizing { cursor: col-resize; user-select: none; }

/* ─── header ──────────────────────────────────────────────────────────── */
.nid-head {
    flex: none;
    padding: 10px 12px 9px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: var(--card);
}
.nid-title-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.nid-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: .1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    font-family: Consolas, "SF Mono", monospace;
}
.nid-spacer { flex: 1; }
.nid-status {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    white-space: nowrap;
}
.nid-conf {
    flex: none;
    font-size: 10.5px;
    color: var(--muted);
    white-space: nowrap;
}
.nid-subline {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    font-size: 11px;
    color: var(--muted);
    min-width: 0;
    overflow: hidden;
}
.nid-subline > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nid-subline-2 { color: var(--muted2); }
.nid-dot::before { content: "·"; color: var(--muted2); margin-right: 8px; }
.nid-mono { font-family: Consolas, "SF Mono", monospace; font-size: 11px; letter-spacing: .2px; }
.nid-guess i { font-style: normal; color: var(--muted2); font-size: 10px; }

/* ─── buttons ─────────────────────────────────────────────────────────── */
.nid-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--btn);
    color: var(--text);
    border-radius: var(--radius);
    height: 30px;
    padding: 0 10px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.nid-btn:hover:not(:disabled) { background: var(--hover); border-color: var(--border2); }
.nid-btn:disabled { opacity: .5; cursor: not-allowed; }
.nid-btn.nid-icon { height: 30px; padding: 0 8px; font-size: 14px; line-height: 1; }
.nid-x { font-size: 16px; }

/* ─── tabs ────────────────────────────────────────────────────────────── */
.nid-tabs {
    flex: none;
    display: flex;
    gap: 2px;
    padding: 6px 10px 0;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    overflow-x: auto;
    scrollbar-width: none;
}
.nid-tabs::-webkit-scrollbar { display: none; }
.nid-tab {
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font: inherit;
    font-size: 12px;
    padding: 6px 8px 7px;
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s ease, border-color .12s ease;
}
.nid-tab:hover { color: var(--text); }
.nid-tab.nid-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ─── body ────────────────────────────────────────────────────────────── */
.nid-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 10px 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--border2) transparent;
}
.nid-body::-webkit-scrollbar { width: 8px; height: 8px; }
.nid-body::-webkit-scrollbar-track { background: transparent; }
.nid-body::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.nid-body::-webkit-scrollbar-thumb:hover { background: var(--muted2); background-clip: padding-box; }

.nid-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 11px 10px;
    margin-bottom: 8px;
    background: var(--card);
}
.nid-section:last-child { margin-bottom: 4px; }
.nid-sec-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--muted);
    margin: 0 0 6px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.nid-sec-title::after { content: ""; flex: 1; height: 1px; background: var(--border2); }

/* ─── property rows (label | value) ───────────────────────────────────── */
.nid-grid { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.nid-kv {
    display: flex;
    gap: 10px;
    align-items: baseline;
    min-height: 28px;
    padding: 5px 0;
    border-bottom: 1px solid var(--border2);
    min-width: 0;
}
.nid-kv:last-child { border-bottom: 0; }
.nid-kv .nid-k { flex: none; width: 116px; color: var(--muted); font-size: 11.5px; }
.nid-kv .nid-v { flex: 1; min-width: 0; font-size: 12px; overflow-wrap: anywhere; }
.nid-ellip { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nid-na { color: var(--muted2); font-style: italic; }
.nid-conf-sub { font-size: 10px; color: var(--muted2); }

/* ─── stacked-списки ──────────────────────────────────────────────────── */
.nid-list { display: flex; flex-direction: column; }
.nid-irow, .nid-nrow, .nid-mrow {
    border-bottom: 1px solid var(--border2);
    padding: 7px 4px 7px 2px;
    min-width: 0;
}
.nid-irow:last-child, .nid-nrow:last-child, .nid-mrow:last-child { border-bottom: 0; }

/* интерфейсы */
.nid-irow { display: flex; align-items: center; gap: 8px; }
.nid-irow-main { flex: 1; min-width: 0; }
.nid-irow-name { display: block; font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nid-irow-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--muted2); font-size: 11px; }
.nid-irow-right { flex: none; font-size: 11px; color: var(--muted); }
.nid-speed { color: var(--text); }

/* соседи */
.nid-nrow-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.nid-nrow-remote { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nid-nrow-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 2px; color: var(--muted2); font-size: 11px; }
.nid-arrow { color: var(--muted2); }

/* MAC-таблица */
.nid-mrow { display: flex; align-items: center; gap: 8px; }
.nid-mrow-main { flex: 1; min-width: 0; }
.nid-mac { display: block; font-size: 12px; font-weight: 500; }
.nid-mrow-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 2px; color: var(--muted2); font-size: 11px; }
.nid-link {
    appearance: none;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-size: 11.5px;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    flex: none;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nid-link:hover { color: var(--text); }

/* ─── evidence table ──────────────────────────────────────────────────── */
.nid-tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.nid-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.nid-table th {
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 7px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.nid-table td { padding: 6px 8px; border-bottom: 1px solid var(--border2); vertical-align: top; }
.nid-table tr:last-child td { border-bottom: 0; }
.nid-table .nid-fact { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nid-table .nid-time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ─── семантика (точки/цвета) ─────────────────────────────────────────── */
.nid-led { width: 7px; height: 7px; border-radius: 50%; background: var(--muted2); flex: none; display: inline-block; }
.nid-led.nid-tone-ok    { background: var(--nid-ok); }
.nid-led.nid-tone-warn  { background: var(--nid-warn); }
.nid-led.nid-tone-bad   { background: var(--nid-bad); }
.nid-led.nid-tone-info  { background: var(--nid-info); }
.nid-led.nid-tone-muted { background: var(--muted2); }
.nid-tone-ok    { color: var(--nid-ok); }
.nid-tone-warn  { color: var(--nid-warn); }
.nid-tone-bad   { color: var(--nid-bad); }
.nid-tone-info  { color: var(--nid-info); }
.nid-tone-muted { color: var(--muted); }

/* ─── notices / empty / loading ───────────────────────────────────────── */
.nid-notice {
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    padding: 8px 10px;
    background: var(--card);
    color: var(--muted);
    font-size: 12px;
}
.nid-notice.nid-tone-bad { border-left-color: var(--nid-bad); }
.nid-notice b { color: var(--text); font-weight: 600; }
.nid-empty {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}
.nid-empty .nid-empty-title { display: block; color: var(--text); font-weight: 600; margin-bottom: 3px; }
.nid-empty.nid-empty-slim { border: 0; padding: 6px 2px; text-align: left; font-size: 11.5px; color: var(--muted); }
.nid-empty-actions { margin-top: 10px; display: flex; justify-content: center; }
.nid-empty.nid-empty-slim + .nid-empty-actions { justify-content: flex-start; }

.nid-skel { display: grid; gap: 8px; }
.nid-skel i {
    display: block;
    height: 14px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--input), var(--hover), var(--input));
    background-size: 200% 100%;
    animation: nid-shimmer 1.2s linear infinite;
}
.nid-skel i:nth-child(1) { width: 55%; }
.nid-skel i:nth-child(2) { width: 80%; }
.nid-skel i:nth-child(3) { width: 68%; }
.nid-skel i:nth-child(4) { width: 74%; }
.nid-skel i:nth-child(5) { width: 48%; }
@keyframes nid-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ─── responsive ──────────────────────────────────────────────────────── */
@media (max-width: 560px) {
    .nid-drawer { width: 100vw; min-width: 0; }
}
@media (max-width: 380px) {
    .nid-kv .nid-k { width: 92px; }
}
@media (prefers-reduced-motion: reduce) {
    .nid-drawer, .nid-overlay, .nid-btn, .nid-tab { transition: none; }
    .nid-skel i { animation: none; }
}
