*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #0b0d14;
    --surface:      #13151f;
    --surface2:     #1c1f2e;
    --surface3:     #242840;
    --border:       #272b3f;
    --border-light: #313654;
    --primary:      #5c7cfa;
    --primary-dim:  rgba(92,124,250,0.12);
    --primary-hover:#4c6ef5;
    --text:         #dde3f0;
    --text-muted:   #6b7a9e;
    --text-faint:   #404666;
    --online:       #34d399;
    --online-dim:   rgba(52,211,153,0.12);
    --offline:      #6b7a9e;
    --offline-dim:  rgba(107,122,158,0.12);
    --warning:      #f59f00;
    --warning-dim:  rgba(245,159,0,0.12);
    --danger:       #f87171;
    --danger-dim:   rgba(248,113,113,0.12);
    --security:     #f59f00;
    --critical:     #f87171;
    --featureupdate:#60a5fa;
    --definition:   #34d399;
    --driver:       #a78bfa;
    --sidebar-w:    230px;
    --topbar-h:     56px;
    --radius:       10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #14172a 0%, #0d0f1a 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width 0.16s ease;
}

/* ── Collapsible sidebar ────────────────────────────────────── */
.layout.nav-collapsed { --sidebar-w: 68px; }

.sidebar-collapse-btn {
    position: absolute;
    top: 22px; right: -12px;
    width: 24px; height: 24px;
    border-radius: 999px;
    background: var(--surface2);
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.sidebar-collapse-btn:hover { color: var(--text); border-color: var(--primary); }

.layout.nav-collapsed .brand-text,
.layout.nav-collapsed li.nav-group-label,
.layout.nav-collapsed .nav-menu li a span:not(.nav-icon),
.layout.nav-collapsed .nav-chevron,
.layout.nav-collapsed .nav-submenu-item,
.layout.nav-collapsed .user-info,
.layout.nav-collapsed .btn-logout span { display: none; }

.layout.nav-collapsed .sidebar-brand { padding: 22px 0 18px; position: relative; }
.layout.nav-collapsed .brand-logo { justify-content: center; }
.layout.nav-collapsed .nav-menu li a { justify-content: center; padding: 9px 0; gap: 0; }
.layout.nav-collapsed .user-card { justify-content: center; padding: 9px; }
.layout.nav-collapsed .btn-logout { display: flex; align-items: center; justify-content: center; }

/* Brand */
.sidebar-brand {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(92,124,250,0.13) 0%, transparent 70%);
    position: relative;
    overflow: hidden;
}

.sidebar-brand::after {
    content: '';
    position: absolute;
    top: -30px; right: -30px;
    width: 100px; height: 100px;
    background: radial-gradient(circle, rgba(92,124,250,0.18) 0%, transparent 70%);
    pointer-events: none;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #5c7cfa 0%, #7c5cfa 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(92,124,250,0.45), 0 0 0 1px rgba(92,124,250,0.25);
}

.brand-text { display: flex; flex-direction: column; gap: 1px; }

.brand-name {
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -0.01em;
    color: #fff;
    line-height: 1.2;
}

.brand-tagline {
    font-size: 10px;
    color: var(--text-faint);
    font-weight: 500;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

/* Nav */
.nav-menu { list-style: none; flex: 1; overflow-y: auto; padding: 8px 0; }

li.nav-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 16px 20px 5px;
    pointer-events: none;
    user-select: none;
}

.nav-menu li a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 20px;
    color: var(--text-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    font-size: 13.5px;
    font-weight: 500;
    transition: color 0.12s, background 0.12s, border-color 0.12s;
}

.nav-menu li a:hover {
    color: var(--text);
    background: rgba(255,255,255,0.04);
    border-left-color: var(--border-light);
}

.nav-menu li a.active {
    color: #fff;
    font-weight: 600;
    background: linear-gradient(90deg, rgba(92,124,250,0.18) 0%, rgba(92,124,250,0.04) 100%);
    border-left-color: var(--primary);
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-menu li a.active .nav-icon { opacity: 1; }

/* Chevron on parent items that have a submenu */
.nav-chevron {
    margin-left: auto;
    font-size: 16px;
    line-height: 1;
    color: var(--text-faint);
    transition: transform 0.18s ease, color 0.12s;
    display: inline-block;
    transform: rotate(0deg);
}

.nav-chevron.open {
    transform: rotate(90deg);
    color: var(--primary);
}

/* Submenu items */
@keyframes submenu-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.nav-submenu-item {
    animation: submenu-in 0.15s ease forwards;
}

.nav-submenu-item a {
    padding-left: 64px;
    font-size: 12.5px;
    color: var(--text-faint);
    border-left-color: transparent;
}

.nav-submenu-item a::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.45;
    flex-shrink: 0;
    transition: opacity 0.12s;
}

.nav-submenu-item a:hover {
    color: var(--text-muted);
    background: rgba(255,255,255,0.03);
    border-left-color: transparent;
}

.nav-submenu-item a.active {
    color: var(--primary);
    background: transparent;
    border-left-color: transparent;
}

.nav-submenu-item a.active::before {
    opacity: 1;
    background: var(--primary);
}

.nav-separator {
    height: 1px;
    background: var(--border);
    margin: 8px 20px;
    list-style: none;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 14px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: rgba(0,0,0,0.15);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 9px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #5c7cfa 0%, #7c5cfa 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}

.user-info { flex: 1; min-width: 0; }

.user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.user-role {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 0;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    width: 100%;
    transition: all 0.12s;
    letter-spacing: 0.02em;
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-dim);
}

/* Language selector (sidebar footer + login card) */
.lang-selector {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
}

.lang-selector .lang-icon {
    font-size: 13px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.lang-select {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 8px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.12s;
}

.lang-select:hover {
    border-color: var(--accent, #5c7cfa);
    color: var(--text);
}

.lang-select option { color: initial; }

.layout.nav-collapsed .lang-selector .lang-icon { display: none; }

/* On the login card the selector centers under the form */
.login-card .lang-selector {
    margin-top: 18px;
    justify-content: center;
}
.login-card .lang-select { flex: 0 0 auto; }

/* ── Main area ───────────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; transition: margin-left 0.16s ease; }

.topbar {
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 32px;
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 12px;
}

.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-subtitle { font-size: 12px; color: var(--text-muted); margin-left: auto; }

.content-area { padding: 28px 32px; }

/* ── Typography ──────────────────────────────────────────────── */
h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
h2 { font-size: 15px; font-weight: 600; margin: 28px 0 14px; color: var(--text); }
h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Title/description on top, then the Actions / "New …" row beneath it, left-aligned. */
.page-header { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; margin-bottom: 24px; }
.page-header h1 { margin-bottom: 0; }
.page-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; margin-top: -4px; }

/* ── Stat cards ──────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.15s, transform 0.15s;
}

.stat-card:hover { transform: translateY(-1px); }
a.stat-card { color: inherit; text-decoration: none; display: block; }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-icon {
    font-size: 22px;
    position: absolute;
    top: 18px;
    right: 18px;
    opacity: 0.3;
}

.stat-value {
    font-size: 38px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-online::before   { background: var(--online); }
.stat-offline::before  { background: var(--offline); }
.stat-alerts::before   { background: var(--danger); }
.stat-warning::before  { background: var(--warning); }
.stat-info::before     { background: var(--primary); }
.stat-patches::before  { background: var(--warning); }
.stat-download::before { background: var(--primary); }

.stat-online .stat-value   { color: var(--online); }
.stat-offline .stat-value  { color: var(--offline); }
.stat-alerts .stat-value   { color: var(--danger); }
.stat-warning .stat-value  { color: var(--warning); }
.stat-info .stat-value     { color: var(--primary); }
.stat-patches .stat-value  { color: var(--warning); }
.stat-download .stat-value { color: var(--primary); }

.stat-online   { border-color: rgba(52,211,153,0.2); }
.stat-offline  { border-color: var(--border); }
.stat-alerts   { border-color: rgba(248,113,113,0.2); }
.stat-warning  { border-color: var(--warning-dim); }
.stat-info     { border-color: var(--primary-dim); }
.stat-patches  { border-color: rgba(245,159,0,0.2); }
.stat-download { border-color: var(--primary-dim); }

.stat-download-wide {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 32px;
    padding: 16px 20px;
}
.stat-download-wide .stat-icon { position: static; opacity: 1; font-size: 26px; }
.stat-download-wide .stat-value { margin-bottom: 2px; }
.stat-download-wide .stat-label { text-transform: none; letter-spacing: normal; font-size: 13px; }

/* ── Section header ──────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h2 { margin: 0; }

.section-count {
    font-size: 12px;
    color: var(--text-faint);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
    font-weight: 500;
}

/* ── Patch group accordion ───────────────────────────────────── */
.patch-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    margin-top: 14px;
    user-select: none;
}
.patch-group-header:hover { background: var(--surface3, var(--surface2)); }
.patch-group-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.patch-group-counts {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }

.data-table th {
    background: var(--surface2);
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-faint);
    letter-spacing: 0.07em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.data-table td {
    padding: 11px 16px;
    border-top: 1px solid var(--border);
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table td.actions-cell { overflow: visible; white-space: normal; display: flex; gap: 6px; justify-content: flex-end; }

/* Row-select checkbox column: shrink padding so the column reads as a
   checkbox, not a text column — applies everywhere a table's first cell
   is just a select-all/select-row checkbox, no markup changes needed. */
.data-table th:has(> input[type="checkbox"]),
.data-table td:has(> input[type="checkbox"]) {
    width: 20px;
    max-width: 20px;
    padding: 3px 0 !important;
    text-align: center;
    overflow: visible;
}
.data-table th:has(> input[type="checkbox"]) > input,
.data-table td:has(> input[type="checkbox"]) > input {
    width: 12px;
    height: 12px;
    margin: 0 auto;
    vertical-align: middle;
    display: block;
}
/* The column right after a checkbox column carries its own 16px left
   padding on top of the checkbox column's padding, which reads as extra
   dead space next to a checkbox — tighten it specifically here. */
.data-table th:has(> input[type="checkbox"]) + th,
.data-table td:has(> input[type="checkbox"]) + td {
    padding-left: 6px;
}

.data-table tbody tr:first-child td { border-top: none; }
.data-table tbody tr:hover td { background: var(--surface2); }
.data-table tbody tr.row-selected td { background: var(--primary-dim); }
.data-table tbody tr.row-selected:hover td { background: rgba(92,124,250,0.18); }
.data-table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.data-table a:hover { text-decoration: underline; }
.data-table a.btn { color: inherit; text-decoration: none; }
.data-table a.btn-primary { color: #fff; }
.data-table a.btn-ghost { color: var(--text-muted); }

.clickable-row { cursor: pointer; }
.clickable-row.row-expanded td { background: var(--surface2); }
.expand-chevron { font-size: 9px; opacity: 0.5; margin-right: 4px; }
.collapsible-heading { cursor: pointer; user-select: none; }

.output-row td { padding: 0 !important; border-top: none !important; }
.output-row:hover td { background: transparent !important; }
.output-panel { padding: 12px 20px 16px; background: var(--surface2); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.output-section { display: flex; flex-direction: column; gap: 4px; }
.output-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.output-label-err { color: var(--danger); }
.output-pre { margin: 0; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); font-family: monospace; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; color: var(--text); max-height: 300px; overflow-y: auto; }
.output-pre-err { color: var(--danger); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-online    { background: var(--online-dim);   color: var(--online);   }
.badge-offline   { background: var(--offline-dim);  color: var(--offline);  }
.badge-pending   { background: var(--warning-dim);  color: var(--warning);  }
.badge-revoked   { background: var(--danger-dim);   color: var(--danger);   }
.badge-completed { background: var(--online-dim);   color: var(--online);   }
.badge-failed    { background: var(--danger-dim);   color: var(--danger);   }
.badge-timedout  { background: var(--danger-dim);   color: var(--danger);   }
.badge-running   { background: var(--primary-dim);  color: var(--primary);  }
.badge-security     { background: var(--warning-dim);         color: var(--security);     }
.badge-critical     { background: var(--danger-dim);          color: var(--critical);     }
.badge-featureupdate{ background: rgba(96,165,250,0.12);      color: var(--featureupdate);}
.badge-definition   { background: var(--online-dim);          color: var(--definition);   }
.badge-driver       { background: rgba(167,139,250,0.12);     color: var(--driver);       }
.badge-update       { background: rgba(148,163,184,0.12);     color: #94a3b8;             }
.badge-unknown      { background: var(--surface3);            color: var(--text-muted);   }
.badge-level-info     { background: var(--primary-dim);  color: var(--primary);  }
.badge-level-warning  { background: var(--warning-dim);  color: var(--warning);  }
.badge-level-error    { background: var(--danger-dim);   color: var(--danger);   }
.badge-level-critical { background: var(--danger);       color: #fff;            }
.badge-success        { background: var(--online-dim);   color: var(--online);   }
.badge-danger         { background: var(--danger-dim);   color: var(--danger);   }

.row-success td:first-child { border-left: 3px solid var(--online); }
.row-danger  td:first-child { border-left: 3px solid var(--danger); }

.text-muted { color: var(--text-muted); }

/* ── Detail cards ────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }

.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; }
dt { color: var(--text-muted); font-size: 12px; display: flex; align-items: center; }
dd { font-weight: 500; font-size: 13px; }
.dd-stack { display: flex; flex-direction: column; gap: 2px; }
.sub-info { font-size: 11px; font-weight: 400; color: var(--text-muted); }

/* ── Metrics ─────────────────────────────────────────────────── */
.metric-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.metric-bar > span:first-child { width: 48px; color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0; }
.metric-bar > span:last-child { width: 200px; flex-shrink: 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.bar { flex: 1; min-width: 60px; height: 6px; background: var(--surface3); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.4s ease; }
.bar-fill-warn   { background: var(--warning); }
.bar-fill-danger { background: var(--danger); }

/* ── Tabs ────────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 28px 0 24px;
    overflow-x: auto;
    width: fit-content;
    max-width: 100%;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.tab-btn:hover {
    background: var(--surface3);
    color: var(--text);
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    border-color: rgba(0,0,0,0.12);
    box-shadow: 0 2px 8px rgba(92,124,250,0.35);
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    background: var(--surface3);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-faint);
    padding: 0 5px;
    line-height: 1;
}

.tab-btn.active .tab-count {
    background: rgba(255,255,255,0.22);
    color: #fff;
}

.btn .tab-count { margin-left: 6px; }
.btn-primary .tab-count {
    background: rgba(255,255,255,0.22);
    color: #fff;
}
.btn-ghost .tab-count {
    background: var(--surface3);
    color: var(--text-muted);
}

/* ── Period selector ────────────────────────────────────────── */
.period-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 20px;
}
.period-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 4px;
}
.period-btn {
    padding: 5px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.period-btn:hover { background: var(--surface3); color: var(--text); }
.period-btn.active {
    background: var(--primary-dim);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

/* ── Metric charts ───────────────────────────────────────────── */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 20px 10px;
    margin-bottom: 14px;
}
.chart-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
}
.chart-label { font-size: 14px; font-weight: 600; color: var(--text); }
.chart-stat  { font-size: 12px; color: var(--text-muted); }
.chart-svg {
    width: 100%;
    height: 80px;
    display: block;
    border-radius: 4px;
    background: var(--surface2);
}
.chart-xlabels {
    display: flex;
    justify-content: space-between;
    padding: 6px 2px 0;
    font-size: 11px;
    color: var(--text-faint);
}

/* ── PS Console ──────────────────────────────────────────────── */
.section { margin-top: 28px; }

.ps-console {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Remote desktop (MeshCentral viewer, embedded cross-origin). Fixed viewport-
   relative height rather than flex: the viewer sizes its canvas to the frame it
   is given, so a collapsing parent leaves it with nothing to draw into. */
.remote-frame {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    height: calc(100vh - 320px);
    min-height: 420px;
}

.remote-frame iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.ps-console-header {
    padding: 10px 14px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ps-console-body { padding: 14px; }

.ps-input {
    width: 100%;
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 6px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.12s;
}

.ps-input:focus { outline: none; border-color: var(--primary); }

.ps-monaco {
    position: relative;
    width: 100%;
    height: 140px;
    border: 2px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.12s;
}

/* BlazorMonaco's host div (id="ps-script-editor") has no intrinsic size of its
   own — without this it collapses to near-0 height (its content is injected by
   JS after the fact), so Monaco measures/creates itself against a ~0px box
   instead of inheriting .ps-monaco's explicit 140px. */
.ps-monaco > div {
    width: 100%;
    height: 100%;
}

.ps-monaco:focus-within { border-color: var(--primary); }

.ps-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center; }

.ps-actions select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
}

.command-history { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }

.command-result {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.cmd-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    background: var(--surface3);
    border-bottom: 1px solid var(--border);
}

.cmd-header code { flex: 1; font-size: 12px; color: var(--text-muted); font-family: 'Cascadia Code', 'Consolas', monospace; }
.cmd-time { font-size: 11px; color: var(--text-faint); white-space: nowrap; }

.cmd-output {
    background: var(--bg);
    padding: 12px 14px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 12.5px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 320px;
    overflow-y: auto;
    color: var(--text);
}

.cmd-error {
    background: rgba(248,113,113,0.06);
    border-top: 1px solid rgba(248,113,113,0.15);
    padding: 10px 14px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 12.5px;
    color: var(--danger);
    white-space: pre-wrap;
}

/* ── Login ───────────────────────────────────────────────────── */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg);
    background-image: radial-gradient(ellipse at 50% 0%, rgba(92,124,250,0.08) 0%, transparent 60%);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 44px 40px;
    width: 400px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 28px;
}

.login-logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 0 20px rgba(92,124,250,0.5);
}

.login-card h1 { font-size: 20px; margin-bottom: 0; }
.login-card h2 { font-size: 13px; font-weight: 400; color: var(--text-muted); margin-bottom: 28px; text-align: center; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-control { width: 100%; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 9px 12px; border-radius: 7px; font-size: 14px; transition: border-color 0.12s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(92,124,250,0.12); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.12s;
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(92,124,250,0.3); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); }
.btn-block { width: 100%; justify-content: center; margin-top: 6px; padding: 10px; font-size: 14px; }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: rgba(247,126,126,0.12); }
.btn-danger-outline:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Selection actions bar ──────────────────────────────────── */
.selection-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.selection-actions-count { font-size: 13px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.btn-action { background: var(--surface2); color: var(--text); border: 1px solid var(--border-light); gap: 6px; }
.btn-action:hover:not(:disabled) { background: var(--surface3); border-color: var(--primary); color: var(--text); }
.btn-action:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-action.open { background: var(--surface3); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }
.btn-action .chevron { font-size: 9px; color: var(--text-muted); transition: transform 0.15s; }
.btn-action.open .chevron { transform: rotate(180deg); }
.dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; background: var(--surface2); border: 1px solid var(--border-light); border-radius: var(--radius); min-width: 200px; box-shadow: 0 12px 32px rgba(0,0,0,0.45); z-index: 200; padding: 4px 0; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: none; padding: 10px 14px; font-size: 13px; color: var(--text); cursor: pointer; border-radius: 0; }
.dropdown-item:hover { background: var(--surface3); color: var(--text); }
.dropdown-item-danger { color: var(--danger); }
.dropdown-item-icon { font-size: 14px; opacity: 0.7; }

/* ── Inline action panel ─────────────────────────────────────── */
.action-panel { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid rgba(92,124,250,0.35); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.action-panel-label { font-size: 13px; font-weight: 600; color: var(--primary); white-space: nowrap; }
.action-panel select { background: var(--surface2); border: 1px solid var(--border-light); color: var(--text); padding: 7px 10px; border-radius: 7px; font-size: 13px; min-width: 180px; }
.action-panel select:focus { outline: none; border-color: var(--primary); }
.action-panel select:disabled { opacity: 0.4; cursor: not-allowed; }
.action-panel-sep { width: 1px; height: 24px; background: var(--border); margin: 0 2px; }

/* ── Misc ────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-error   { background: var(--danger-dim);  border: 1px solid rgba(248,113,113,0.25); color: var(--danger);  }
.alert-success { background: var(--online-dim); border: 1px solid rgba(52,211,153,0.25);  color: var(--online);  }

.empty-state { color: var(--text-muted); text-align: center; padding: 48px; font-size: 13px; }

.search-input { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 7px; font-size: 13px; }
.search-input:focus { outline: none; border-color: var(--primary); }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.form-static { font-size: 14px; color: var(--text); padding: 9px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; min-height: 38px; }

.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.filter-bar select { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: 7px; font-size: 13px; }

.settings-section { margin-bottom: 44px; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.settings-card {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.12s, transform 0.12s, background 0.12s;
}

.settings-card:hover {
    transform: translateY(-1px);
    border-color: var(--border-light);
    background: var(--surface2);
}

.settings-card.active {
    border-color: var(--primary);
    background: linear-gradient(180deg, rgba(92,124,250,0.12) 0%, rgba(92,124,250,0.04) 100%);
}

.settings-card h2 {
    margin: 0 0 6px;
}

.settings-card p {
    color: var(--text-muted);
    font-size: 13px;
}

.settings-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface3);
    font-size: 18px;
    flex-shrink: 0;
}

.token-value {
    word-break: break-all;
    user-select: all;
}

.token-copy {
    margin-left: 8px;
}

small { font-size: 12px; color: var(--text-muted); font-weight: 400; margin-left: 8px; }
pre { font-family: 'Cascadia Code', 'Consolas', monospace; }
code { font-family: 'Cascadia Code', 'Consolas', monospace; font-size: 12px; }

/* ── Group criteria builder ──────────────────────────────────── */
.group-form { max-width: 560px; }

.criteria-list { display: flex; flex-direction: column; gap: 8px; }

.criterion-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    flex-wrap: wrap;
}

.criterion-row select,
.criterion-row input[type="text"],
.criterion-row input[type="number"] {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: 7px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.12s;
}

.criterion-row select:focus,
.criterion-row input:focus { border-color: var(--primary); }

.criterion-field    { min-width: 170px; }
.criterion-operator { min-width: 155px; }
.criterion-value    { flex: 1; min-width: 140px; }
.remove-criterion   { margin-left: auto; flex-shrink: 0; }

.criterion-join {
    align-self: flex-start;
    margin: 0 0 0 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--primary);
    font-weight: 600;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 7px;
    outline: none;
}

/* Criteria summary badges */
.criteria-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.criteria-badge {
    font-size: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

.criteria-join {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-faint);
    letter-spacing: 0.03em;
}

.criteria-badge-more {
    background: var(--surface3);
    color: var(--text-faint);
}

/* ── Sortable table headers ──────────────────────────────────── */
.th-sort { cursor: pointer; user-select: none; transition: background 0.15s, color 0.15s; }
.th-sort:hover { color: var(--text); background: var(--surface3); }
.th-sort.sort-active {
    color: var(--primary);
    background: var(--primary-dim);
    box-shadow: inset 0 -2px 0 var(--primary);
}
.sort-icon { color: var(--text-faint); font-size: 9px; margin-left: 4px; opacity: 0.4; vertical-align: middle; }

/* Column resize handle */
.col-resize-handle {
    position: absolute;
    top: 0; right: 0;
    width: 8px; height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 1;
}
.col-resize-handle:hover,
.col-resize-handle.dragging {
    background: var(--primary);
    opacity: 0.5;
}

.th-sort:hover .sort-icon { opacity: 0.7; }
.th-sort.sort-active .sort-icon { color: var(--primary); font-size: 11px; opacity: 1; vertical-align: middle; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Policy form ─────────────────────────────────────────────── */
.policy-form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}
.policy-form-section-header {
    padding: 12px 20px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.policy-form-section-body { padding: 20px; }

.policy-action-select {
    background: var(--surface2);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text);
    font-size: 12px;
    min-width: 230px;
    cursor: pointer;
}
.policy-action-select:focus { outline: none; border-color: var(--primary); }

.policy-schedule-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.policy-schedule-label { color: var(--text-muted); font-size: 13px; }
.policy-schedule-select {
    background: var(--surface2);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}
.policy-schedule-select:focus { outline: none; border-color: var(--primary); }
.policy-time-input {
    background: var(--surface2);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
    width: 100px;
}
.policy-time-input:focus { outline: none; border-color: var(--primary); }

.policy-reboot-info {
    background: var(--primary-dim);
    border: 1px solid rgba(92,124,250,0.25);
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.policy-reboot-info strong { color: var(--primary); }

.policy-assign-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.policy-assign-panel {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.policy-assign-header {
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.policy-assign-count { color: var(--text-faint); }
.policy-assign-count.has-sel { color: var(--primary); }
.policy-assign-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.policy-assign-list { max-height: 160px; overflow-y: auto; padding: 4px 0; }
.policy-assign-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.policy-assign-item:hover { background: var(--surface3); }
.policy-assign-item input[type=checkbox] { accent-color: var(--primary); cursor: pointer; }
.device-status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    flex-shrink: 0;
}
.device-status-dot.online { background: var(--online); }

/* ── Patch install progress (indeterminate) ───────────────── */
.patch-install-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}
.patch-progress-bar {
    position: relative;
    flex: 1;
    height: 6px;
    background: var(--primary-dim);
    border-radius: 3px;
    overflow: hidden;
}
.patch-progress-bar span {
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    animation: patch-indeterminate 1.1s ease-in-out infinite;
}
@keyframes patch-indeterminate {
    0%   { left: -40%; }
    100% { left: 100%; }
}
.patch-progress-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
